Important: Please read the Qt Code of Conduct -

QDockWidget - how to tell if it is tabbed under or closed

  • Hello,

    I want to determine if a QDockWidget is visible and if not if it is not visible because it is closed or because it is tabbed and underneath another QDockWidget.
    How can I tell the difference?

    isVisible() returns false in both cases.

    If I instead use tabifiedDockWidgets(QDockWidget) to check if the widget is docked together with other widgets also the ones that are not tabified but have been in the dock previously and then got closed will show up as well.

    So how can I tell the difference?

  • Lifetime Qt Champion


    Can you explain what difference it makes ?

  • I want to make the two following things:

    • If a Dockwidget is docked alone then the objectname in the titleBarWidget should be shown. If there is a tab (tabbar position north) then only the title in the tab, not again on the titlebarwidget shoult be shown.

    • I want to have a menu, where all the available dockwidgets are shown and are checkable. Depending on weather they are open or not they should be shown as checked/unchechecked, so I can restore them when they are closed.

  • Lifetime Qt Champion

    QDockWidget already provides a QAction for that.

  • Thanks for the hint with the QDockWidget::toggleViewAction()
    However this does not solve the problem with the double object name in the tiltebar and the tab.
    (Except I do some hack using the check-state from the action)

  • Lifetime Qt Champion

    @gde23 said in QDockWidget - how to tell if it is tabbed under or closed:


    Just one thing, do you mean this methods return more than the docks currently tabbed with the one you are requesting the information from ?

  • Kind of.
    tabifiedDockWidgets() returns the Dockwidegts that are tabbed together with the one I request tabifiedDockWidgets() from. But also the widgets that were in the same dock, but then were closed. Pressing the (X)-Button just calls hide(), so I can reopen them when needed without loosing the Information in them, maybe I have implemented this wrong?

    EDIT: even if I just drag and drop the widgets out the one in the dock still "sees" the others beeing there but not the other way round.


    Widegt1 + Wigdet2+ WIdget3 all in one dock
    Then I drag and drop Widget1 and Widget2 to be floating, leaving only Widget3 in dock and print the output

        QList<NiceDockWidget*> dock_widgets = findChildren<NiceDockWidget*>();
        for(int i=0; i<dock_widgets.size(); i++)
            std::cout << "----" << dock_widgets[i]->objectName().toStdString() << std::endl;
            QList<QDockWidget*> sibling_dock_widgets = tabifiedDockWidgets(dock_widgets[i]);
            for(int j=0; j<sibling_dock_widgets.size(); j++)
                std::cout << sibling_dock_widgets[j]->objectName().toStdString() << std::endl;

    Output is:

    so Widget3 still thinks that Widget1 and Widegt2 are in the dock as well.

    Also if I close Widegt1 and Widget2 tabifiedDockWidgets(Widget3) still returns them

  • Lifetime Qt Champion

    Can you provide a minimal compilable example that shows that behaviour ?

  • @SGaist Here is a zip file with a minimal working example.
    To test it just drag all three Docks to a DockWidgetArea so they get tabbed.
    Then drag one widget back to floating.

    Now tabifiedDockWidgets() will return no widgets for the floating one (see qDebug() output). This is how it should be.

    However, tabifiedDockWidgets() will return the floating widget when called for one of the other widgets. This is wrong in my opinion.

Log in to reply