PDA

View Full Version : Setting the active tab with tabified docking windows



krippy2k
29th May 2009, 10:57
Hi all,

Okay I've got an application that has some widgets that are docked and tabified using QMainWindow::tabifyDockWidget. The problem I have is that the tab on the right becomes the active tab and I need the tab on the left to be the active tab when the application starts, and I don't see any way to set the active tab. Also it would be convenient to be able to make different tabs active based upon other user input at runtime.

Any ideas on what I need to do to handle this would be most appreciated.

Thanks

krippy2k
29th May 2009, 11:52
Okay I figured out a very hacky way of doing this, but if somebody knows of a cleaner way then please let me know.



void VisualCurryApp::setActiveDockTab( const QDockWidget* dock )
{
QList<QTabBar*> tabBars = findChildren<QTabBar*>();
foreach( QTabBar* bar, tabBars )
{
int count = bar->count();
for (int i = 0; i < count; i++)
{
QVariant data = bar->tabData(i);
QVariant::DataPtr dataPtr = data.data_ptr();
if (dataPtr.data.ptr == dock)
{
bar->setCurrentIndex(i);
}
}
}
}


Thanks

dethtoll
23rd March 2017, 18:22
This is old, but still shows up in related Google searches. For anyone else who stumbles on this, the delayed-raise approach suggested here worked for me: http://www.qtcentre.org/threads/47927-How-to-set-focus-(select)-a-tabbed-QDockWidget

Unfortunately, it seems that calling raise() immediately still doesn't work in Qt 5.8 under Windows 10.