Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Class to add a footer to the QTabWidget widgets
Qt 6.12 LTS is out! See what's new in the release blog

Class to add a footer to the QTabWidget widgets

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 498 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    odelaune
    wrote on last edited by
    #1

    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.

    jsulmJ 1 Reply Last reply
    0
    • O odelaune

      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.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

      @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.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      O 1 Reply Last reply
      2
      • jsulmJ jsulm

        @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 Offline
        O Offline
        odelaune
        wrote on last edited by
        #3

        @jsulm said in Class to add a footer to the QTabWidget widgets:

        @odelaune Simply put your QTabWidget and and the TabFooter in same vertical layout...

        Oh, yes of course.
        Thank you.

        1 Reply Last reply
        0
        • O odelaune has marked this topic as solved on

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt
        • Unsolved