PDA

View Full Version : QTabWidget delete order



Alundra
19th September 2015, 14:13
Hi,
Does a QTabWidget remove the tab from the last to the first when it's deleted ?
The only way to remove one tab at the end is to use an event to know when it's closed and close all other ?
Thanks

anda_skoa
19th September 2015, 20:10
Does a QTabWidget remove the tab from the last to the first when it's deleted ?

From the code it looks like the internal stack widget deletes the widgets on destruction, in the order of the stack/tabs.
But that should be easy enough to test, right



The only way to remove one tab at the end is to use an event to know when it's closed and close all other ?

Not sure what you mean.
To remove the last tab, you call removeTab() with the last index, which is count() - 1.

Cheers,
_

Alundra
19th September 2015, 20:28
I mean for example remove all other tab and the index 1 at the end, no way to set one tab which will be removed after all other ?

anda_skoa
19th September 2015, 21:48
I am still not sure what you mean.

if you want to remove alll but one tab, you could get that tab's widget, remove that tab, then clear the tab widget and re-add the one tab.

Or with two loops


// remove all tabs before the one to keep
for (int = 0; i < indexToKeep; ++i) {
tabWidget->removeTab(0);
}
// remove all tabs after the one to keep
while (tabWidget->count() > 1) {
tabWidget->removeTab(1);
}


Cheers,
_

Alundra
19th September 2015, 23:04
I have one window which contains multiple window, it's a tabbed window I made, but all other tab depend of one tab and if this tab is removed all other has to be removed before.
Actually tabs are not movable because when I drag out one tab to make it floatable I got an assert, looks like a bug from Qt, but not sure.
So, actually the main tab is always the first so it's not a problem but if a day tab can be movable, the main tab could not be first.
Other way is to make this tab not movable and all other movable possible if Qt allows.
I will surely post the issue which cause an assert but it's not the topic here...

anda_skoa
20th September 2015, 09:27
QTabBar has a signal for when tabs are moved so you should be able to keep the index of the "first tab" updated.

Or you just keep a pointer to that tab's widget and query its current index with QTabWidget::indexOf() before starting removing.

Cheers,
_