Skip to content

Conversation

@nickdademo
Copy link

It is possible to create a setFocus() recursion under the following conditions:

CDockManager::FocusHighlighting = true
CDockManager::eConfigFlag::AllTabsHaveCloseButton = true
CDockManager::eConfigFlag::TabCloseButtonIsToolButton = true

with one dock widget set as the central widget and the other docks tabbed in the same area.

Reproduced with CentralWidgetExample:

ezgif-3-e6831d590c48

@nickdademo
Copy link
Author

nickdademo commented Oct 19, 2020

This occurs because both focusedOld and focusedNow are close buttons - resulting in a never-ending setFocus loop.

Modified demo code to reproduce:

CMainWindow::CMainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::CMainWindow)
{
    ui->setupUi(this);
    CDockManager::setConfigFlag(CDockManager::OpaqueSplitterResize, true);
    CDockManager::setConfigFlag(CDockManager::XmlCompressionEnabled, false);
    CDockManager::setConfigFlag(CDockManager::FocusHighlighting, true);
    CDockManager::setConfigFlag(CDockManager::AllTabsHaveCloseButton, true); // ADDED
    CDockManager::setConfigFlag(CDockManager::TabCloseButtonIsToolButton, true); // ADDED
    DockManager = new CDockManager(this);

    // Set central widget
    QPlainTextEdit* w = new QPlainTextEdit();
	w->setPlaceholderText("This is the central editor. Enter your text here.");
    CDockWidget* CentralDockWidget = new CDockWidget("CentralWidget");
    CentralDockWidget->setWidget(w);
    auto* CentralDockArea = DockManager->setCentralWidget(CentralDockWidget);
    CentralDockArea->setAllowedAreas(DockWidgetArea::OuterDockAreas);

    // create other dock widgets
    QTreeView* fileTree = new QTreeView();
    fileTree->setFrameShape(QFrame::NoFrame);
    QFileSystemModel* fileModel = new QFileSystemModel(fileTree);
    fileModel->setRootPath(QDir::currentPath());
    fileTree->setModel(fileModel);
    CDockWidget* DataDockWidget = new CDockWidget("File system");
    DataDockWidget->setWidget(fileTree);
    DataDockWidget->resize(150, 250);
    DataDockWidget->setMinimumSize(100, 250);
    auto* fileArea = DockManager->addDockWidgetTabToArea(DataDockWidget, CentralDockArea); // CHANGED
    ui->menuView->addAction(DataDockWidget->toggleViewAction());

    QTableWidget* table = new QTableWidget();
    table->setColumnCount(3);
    table->setRowCount(10);
    CDockWidget* TableDockWidget = new CDockWidget("Table");
    TableDockWidget->setWidget(table);
    TableDockWidget->setMinimumSizeHintMode(CDockWidget::MinimumSizeHintFromDockWidget);
    TableDockWidget->resize(250, 150);
    TableDockWidget->setMinimumSize(200,150);
    DockManager->addDockWidgetTabToArea(TableDockWidget, CentralDockArea); // CHANGED
    ui->menuView->addAction(TableDockWidget->toggleViewAction());

    QTableWidget* propertiesTable = new QTableWidget();
    propertiesTable->setColumnCount(3);
    propertiesTable->setRowCount(10);
    CDockWidget* PropertiesDockWidget = new CDockWidget("Properties");
    PropertiesDockWidget->setWidget(propertiesTable);
    PropertiesDockWidget->setMinimumSizeHintMode(CDockWidget::MinimumSizeHintFromDockWidget);
    PropertiesDockWidget->resize(250, 150);
    PropertiesDockWidget->setMinimumSize(200,150);
    DockManager->addDockWidgetTabToArea(PropertiesDockWidget, CentralDockArea); // CHANGED
    ui->menuView->addAction(PropertiesDockWidget->toggleViewAction());

    createPerspectiveUi();
}

@githubuser0xFFFF
Copy link
Owner

Thank you for this fix.

@githubuser0xFFFF githubuser0xFFFF merged commit 8f95447 into githubuser0xFFFF:master Oct 23, 2020
luelista pushed a commit to luelista/Qt-Advanced-Docking-System that referenced this pull request Mar 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants