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
Thanks
-
Ok I can now demonstrate my problem -
In my class I have
@
TabWidgetTest::TabWidgetTest(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);m_dockWidgets.append(new QDockWidget("Dock 1",this));
m_dockWidgets.last()->setWidget(new Dock1Content(this));
addDockWidget(Qt::BottomDockWidgetArea,m_dockWidgets.last());
m_dockWidgets.last()->setAllowedAreas(Qt::BottomDockWidgetArea);m_action1 = m_dockWidgets.last()->toggleViewAction();
m_action1->setData(0);
connect(m_action1,&QAction::toggled,this,&TabWidgetTest::onViewToggled);m_dockWidgets.append(new QDockWidget("Dock 2",this));
m_dockWidgets.last()->setWidget(new Dock2Content(this));
addDockWidget(Qt::BottomDockWidgetArea,m_dockWidgets.last());
m_dockWidgets.last()->setAllowedAreas(Qt::BottomDockWidgetArea);m_action2 = m_dockWidgets.last()->toggleViewAction();
m_action2->setData(1);
connect(m_action2,&QAction::toggled,this,&TabWidgetTest::onViewToggled);tabifyDockWidget(m_dockWidgets[0],m_dockWidgets[1]);
}@In the slot I have
@
{
QList<QTabBar*> tabBarList = findChildren<QTabBar*>();
QTabBar* tabBar = NULL;
if (!tabBarList.isEmpty())
{
tabBar = tabBarList.at(0);
qDebug() << "Count = " << tabBar->count();
}
else
{
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?
Thanks
-
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.