PDA

View Full Version : QTabWidget inside QStackedWidget



zgulser
20th May 2012, 17:28
Hi,

As the subject title implies, I have a QTabWidget inside a QStackedWidget.

When I try to add a new tab by calling the following piece of code;



_ui.tabWidget->addTab(temp, QString::number(p_Cid));


It adds the tab but overrides the most previously added tab. ( Also meaning that shows only the lastly added tab.)

Any ideas?

d_stranz
20th May 2012, 18:50
_ui.tabWidget->addTab(temp, QString::number(p_Cid));

This code implies that the tabWidget is *not* a child of the stack widget, so your UI is probably not defined correctly. If the tab widget was owned by the stack widget, then you would have at least one more level of indirection:


_ui.stackWidget->tabWidget->addTab(temp, QString::number(p_Cid));

or, if the same thing was assembled via code:



QStackedWidget * stack = new QStackedWidget( mainWidget );
QTabWidget * tabWidget = new QTabWidget( stack );
tabWidget->addTab( temp, QString::number( p_Cid ) );
tabWidget->addTab( temp2, QString::number( p_Cid2 ); //etc.
stack->addWidget( tabWidget );


And another question - what is "temp"? Is it a unique, new widget pointer that will end up being owned by the tab widget, or are you mistakenly trying to put the same widget instance into multiple tabs? If that's what you're doing, the tab widget probably sees the mistake and deletes the previous tab, since you can't add the same widget instance more than once.

zgulser
21st May 2012, 09:38
Hi,



... or are you mistakenly trying to put the same widget instance into multiple tabs? If that's what you're doing, the tab widget probably sees the mistake and deletes the previous tab, since you can't add the same widget instance more than once.


I don't think that should be a mistake. After all we may just want to play with one reference widget upon tab changes in the name of memory efficiency.

Anyway, if that's the case, i let you know.

Thanks.