Multiple tabbed QDockWidget and default selection
Hi,
I created several QDockWidget which are tabbified by default using this :
Code:
mainWindow_->tabifyDockWidget(prevDock, dock);
When the aplication starts, this is the last tab which is selected by default. I want to have the FIRST tab selected instead.
Using on first tab/dock does not change anything.
Any idea ?
BR
Re: Multiple tabbed QDockWidget and default selection
After a LOT of searching I finally came up with a work around that mostly works. It's cumbersome. I basically, get all of the tabBars in my main window and check their children until I find the QTabBar that contains my dock widgets. (I couldn't get to the QDockWidgets by grabbing the tab bar so I check the tabText to see if the tab label is what I expect.) Then, I call setCurrentIndex on that tabBar to select the desired tabe thus putting my QDockWidget on top.
The other issue I ran into is that I couldn't do this while still in my project open slot (the tabbar had not finished updating.) To get around this I set a timer. When the timer fires I'm able to go through the process I explain above, and the desired tab is on top.
I do hope that an api method is added to handle this more simply.
Re: Multiple tabbed QDockWidget and default selection
firstTab->show();
firstTab->raise();
Re: Multiple tabbed QDockWidget and default selection
thanks srazi.. your solution is great....
Re: Multiple tabbed QDockWidget and default selection
It does not work for me.
firstTab->raise() has no effect. Any ideas?
Re: Multiple tabbed QDockWidget and default selection
I'm also having an issue with this. I would appreciate any advice on being able to set the current tabbed dockwidget.
Re: Multiple tabbed QDockWidget and default selection
Call QWidget::raise() on the dock widget you want on top. There's not much more to it than that.
Code:
#include <QtGui>
#include <QDebug>
Q_OBJECT
public:
dock1
->setWidget
(new QLabel("Dock 1 content",
this));
addDockWidget(Qt::RightDockWidgetArea, dock1);
dock2
->setWidget
(new QLabel("Dock 2 content",
this));
addDockWidget(Qt::RightDockWidgetArea, dock2);
tabifyDockWidget(dock1, dock2);
flop = true;
connect(&timer, SIGNAL(timeout()), SLOT(flip()));
timer.start(2000);
}
public slots:
void flip() {
if (flop)
dock1->raise();
else
dock2->raise();
flop = !flop;
}
private:
bool flop;
};
int main(int argc, char *argv[])
{
MainWindow m;
m.show();
return app.exec();
}
#include "main.moc"