Hmmm I think that currentChanged() is not be emitted when you move the tab, only when you click on a new one after the tab has been moved.
Hmmm I think that currentChanged() is not be emitted when you move the tab, only when you click on a new one after the tab has been moved.
RobC (9th March 2012)
A very good point. I hadn't tried that when experimenting.
So, ideally a signal on the move - but there isn't one?![]()
I don't think there is.
You could try subclassing the QTabWidget and reimplement void QTabWidget::tabInserted ( int index ) [virtual protected], maybe you can emit the signal from there.
RobC (9th March 2012)
No such luck. It emits a signal when the form is first set, but nothing after that point. I guess it doesn't get used when the tabs are moved. I've tried several ways, to no avail.
Time for Plan B. Well, a cup of tea and then Plan B.
See QTabBar::tabMoved(int, int). QTabWidget::tabBar() is protected so you will still need to subclass QTabWidget.
RobC (9th March 2012)
Forgive the question, but how do I reimplement QTabBar if I subclass QTabWidget?
You don't need to reimplement QTabBar. You just need to be able to call the protected function tabBar() which you can do in a subclass of QTabWidget.
Using your example:HTHQt Code:
#include <QtGui> { Q_OBJECT public: TabWidget() { setMinimumSize(300,100); setMovable(true); for(int i=0;i<5;++i) connect(tabBar(),SIGNAL(tabMoved(int,int)),this,SLOT(relabelTabs(int,int))); } public slots: void relabelTabs(int /* from */, int /* to */){ for(int i=0;i<count();++i) } }; int main(int argc, char *argv[]) { TabWidget tw; tw.show(); app.exec(); } #include "main.moc"To copy to clipboard, switch view to plain text mode
Last edited by norobro; 9th March 2012 at 22:33. Reason: updated contents
RobC (9th March 2012)
Ah, I getcha. Sorted. Thanks for the help folks!
You're welcome.
Rather than iterating over all of the tabs, here's a better version of the slot:Qt Code:
void relabelTabs(int from, int to){ setTabText(from,tabText(to)); setTabText(to,hold); }To copy to clipboard, switch view to plain text mode
Bookmarks