- All (478)
- jom (0)
- Qt Linguist (7)
- Qt Eclipse Integration (9)
- Qt Designer (7)
- Qt Creator (4)
- Qt build system: qmake (31)
- Qt build system: configure (3)
- Qt Assistant (5)
- Printing (4)
- Porting from Qt 3 to Qt 4 (1)
- Plugins (7)
- Qt Visual Studio AddIn (2)
- Qt/MFC Migration (2)
- QtScript (3)
- MDI (2)
- XML (1)
- Widgets (22)
- WebKit (5)
- Tools and Containers (2)
- Threads (2)
- Text Handling (10)
- SQL (6)
- QtTest (1)
- QtService (1)
- Platform: Windows (49)
- Platform: Unix (16)
- Platform: Mac OS X (18)
- Image Formats (2)
- I/O (2)
- Graphicsview (8)
- Font handling (9)
- Event System (18)
- Drag and Drop (4)
- Dialogs (6)
- Desktop integration (3)
- ActiveQt (3)
- Itemviews (60)
- Layout (4)
- Qt Quick (10)
- Qt SDK (1)
- Licensing (2)
- Platform: Embedded Linux (38)
- Painting (32)
- OpenGL (4)
- Object Model (6)
- Network (5)
- Multimedia (3)
- Miscellanous (23)
- Main Window (19)
- Look and Feel (23)
- Development (0)
- Getting Involved (0)
- Routines (0)
How can I check which tab is the current one in a tabbed QDockWidget?
You need to find the QTabBar [doc.qt.nokia.com] that exists for the tabbed dockwidgets and then simply call tabBar->currentIndex() [doc.qt.nokia.com] on it to find the current index and connect a slot to the tabbar’s currentChanged() [doc.qt.nokia.com] slot. The example below shows how you can do this.
- #include <QtGui>
- {
- Q_OBJECT
- public:
- {
- setCentralWidget(w);
- tabifyDockWidget(d0, d1);
- tabifyDockWidget(d1, d2);
- // get the QTabBar
- if(!tabList.isEmpty()){
- tabBar->setCurrentIndex(1);
- qDebug() << currentTab;
- connect(tabBar, SIGNAL(currentChanged(int)), this, SLOT(testSlot(int)));
- }
- }
- public slots:
- void testSlot(int index)
- {
- qDebug() << "current tab is " << index;
- }
- };
- #include "main.moc"
- int main(int argc, char **argv)
- {
- MainWindow mw;
- mw.show();
- return a.exec();
- }

2 comments
October 26, 2010
Lab Rat
Note that you do not need to bind to a slot to find the current active tab. Simply use tabBar.currentIndex() for getting the current active index and setCurrentIndex(int).
View this thread [developer.qt.nokia.com] for more info.
August 16, 2011
Lab Rat
when have a qtabbar whitout qdockwidget,how to distinguish?