Class to add a footer to the QTabWidget widgets
-
Hi there,
I have a QTabWidget that contains 3 tabs. Each tab contains a custom QWidget, let's call them tabA, tabB and tabC. Each custom QWidget does something that is really different from the others.I want to add the same footer to all the custom QWidgets.
I tried something like
m_tab_footer = new TabFooter(this); qobject_cast<tabA*>(ui->text_area->widget(0))->setTabFooter(m_tab_footer); qobject_cast<tabB*>(ui->text_area->widget(1))->setTabFooter(m_tab_footer); qobject_cast<tabC*>(ui->text_area->widget(2))->setTabFooter(m_tab_footer);with setTabFooter defined as
void tabA::setTabFooter(TabFooter* footer) { ui->layout_footer->addWidget(footer); }tabA, tabB and tabC are set for each tab of the QTabWidget in QtDesigner.
Unfortunately, there are several problem. First it is highly redundant and I guess it is possible to factorize. Secondly, it does not work because the footer only appears on the tabC widget, probably because the layout_footer takes the ownership of the TabFooter object.
I guess tabA, tabB and tabC should inherit from a common class that would contain the FooterTab object. Yet, I do not know (probably too tired now) how to integrate the current tabA/tabB/tabC content into this common class.
Thanks for your help.
-
Hi there,
I have a QTabWidget that contains 3 tabs. Each tab contains a custom QWidget, let's call them tabA, tabB and tabC. Each custom QWidget does something that is really different from the others.I want to add the same footer to all the custom QWidgets.
I tried something like
m_tab_footer = new TabFooter(this); qobject_cast<tabA*>(ui->text_area->widget(0))->setTabFooter(m_tab_footer); qobject_cast<tabB*>(ui->text_area->widget(1))->setTabFooter(m_tab_footer); qobject_cast<tabC*>(ui->text_area->widget(2))->setTabFooter(m_tab_footer);with setTabFooter defined as
void tabA::setTabFooter(TabFooter* footer) { ui->layout_footer->addWidget(footer); }tabA, tabB and tabC are set for each tab of the QTabWidget in QtDesigner.
Unfortunately, there are several problem. First it is highly redundant and I guess it is possible to factorize. Secondly, it does not work because the footer only appears on the tabC widget, probably because the layout_footer takes the ownership of the TabFooter object.
I guess tabA, tabB and tabC should inherit from a common class that would contain the FooterTab object. Yet, I do not know (probably too tired now) how to integrate the current tabA/tabB/tabC content into this common class.
Thanks for your help.
-
@odelaune Simply put your QTabWidget and and the TabFooter in same vertical layout...
Also, you CAN'T use same widget instance in more than one place like you're trying right now. That is why it is only visible on tabC. -
O odelaune has marked this topic as solved on