Important: Please read the Qt Code of Conduct -

Dock Widgets and tabs

  • Hi
    In my application I have a set of docked widgets that are all tabbed.
    I have a menu to which I have added the action associated with the docked widget that enables me to toggle the viability of the widgets. This all works fine except for one niggle.
    Say I have 2 out of 3 of my widgets on display and then use the menu to make a 3rd visible. The 3rd widget does get added to the tabbed set of widgets but is not made the current tab.

    Does anyone have any hints on how I can make it the current tab


  • Ok I can now demonstrate my problem -
    In my class I have
    TabWidgetTest::TabWidgetTest(QWidget *parent)
    : QMainWindow(parent)

    m_dockWidgets.append(new QDockWidget("Dock 1",this));
    m_dockWidgets.last()->setWidget(new Dock1Content(this));

    m_action1 = m_dockWidgets.last()->toggleViewAction();

    m_dockWidgets.append(new QDockWidget("Dock 2",this));
    m_dockWidgets.last()->setWidget(new Dock2Content(this));

    m_action2 = m_dockWidgets.last()->toggleViewAction();


    In the slot I have
    QList<QTabBar*> tabBarList = findChildren<QTabBar*>();
    QTabBar* tabBar = NULL;
    if (!tabBarList.isEmpty())
    tabBar =;
    qDebug() << "Count = " << tabBar->count();
    qDebug() << "No tab bar";

    QAction* action = dynamic_cast<QAction*>(sender());

    if (action)
    int data = action->data().toInt();
    qDebug() << checked << " " << data;
    qDebug() << "";
    // m_dockWidgets[data]->raise();

    When the slot is called the tabbed widget that is to be added has not yet been added to the tab bar. and I cannot see a way of catching when a widget has been added to the tab bar.

    Is there a way in which this can be achieved?


  • An ancient topic but one which I just encountered myself.

    Before calling raise();, add a call to qApp->processEvents(); This allows the new tab to render and "exist" before you send the function call to raise it. I am using Qt 5.12.

Log in to reply