Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Hide and show a QTabWidget tab
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Hide and show a QTabWidget tab

Scheduled Pinned Locked Moved General and Desktop
11 Posts 4 Posters 30.4k Views 1 Watching
  • 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.
  • D Offline
    D Offline
    douglaspsilva
    wrote on 17 Oct 2014, 14:20 last edited by
    #1

    How can I set a QTabWidget tab to hidden and after some signal show the same tab again.

    I've tried already to delete it, but couldn't get an object instance copy to add it later.

    Any hint?

    Thanks!

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on 17 Oct 2014, 15:01 last edited by
      #2

      Welcome to Qt DevNet.

      Have you tried tabWidget->tabBar()->hide() ?

      1 Reply Last reply
      0
      • D Offline
        D Offline
        douglaspsilva
        wrote on 17 Oct 2014, 16:07 last edited by
        #3

        Yes, I tried already. But did not work.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          douglaspsilva
          wrote on 17 Oct 2014, 16:10 last edited by
          #4

          I'm not sure if was it's clear, but I want to hide and show a specific tab, not the whole tabBar.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andreyc
            wrote on 17 Oct 2014, 17:52 last edited by
            #5

            Are you talking about something like this
            @
            void Widget::on_pushButton_clicked()
            {
            if (m_hiddenWidget) {
            ui->tabWidget->insertTab(m_hiddenIndex, m_hiddenWidget, m_hiddenLabel);
            m_hiddenWidget = nullptr;
            ui->pushButton->setText("Hide");
            } else {
            m_hiddenWidget = ui->tabWidget->currentWidget();
            m_hiddenIndex = ui->tabWidget->indexOf(m_hiddenWidget);
            m_hiddenLabel = ui->tabWidget->tabText(m_hiddenIndex);
            ui->tabWidget->removeTab(m_hiddenIndex);
            ui->pushButton->setText("Show");
            }
            }
            @

            A N 2 Replies Last reply 18 May 2018, 07:23
            1
            • D Offline
              D Offline
              douglaspsilva
              wrote on 17 Oct 2014, 18:42 last edited by
              #6

              Thank you for the response, but, I think it won't work in my case because into the tab I have a set of widgets which must to be hidden/showed too.

              These tabs were designed using QtCreator and not initialized along with my code, then I do not insert a new tab from my code as it was created before, I thought it would be a matter of setting it as hidden or visible, but it is not looking like so simple.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andreyc
                wrote on 17 Oct 2014, 18:52 last edited by
                #7

                In my example I created QTabWidget in Qt designer.
                Each tab in the QTabWidget is a QWidget that contains other widgets.
                In my example m_hiddenWidget is a QWidget and it keeps all widgets that are in the current widget like edit lines and the labels.
                At the begging m_hiddenWidget is nullptr I use it to keep the content of a hidden tab between remove and insert.

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  douglaspsilva
                  wrote on 17 Oct 2014, 19:13 last edited by
                  #8

                  Ok, I'll try this. When finish it I'll tell you the status.

                  Thanks again.

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    douglaspsilva
                    wrote on 17 Oct 2014, 19:28 last edited by
                    #9

                    Thank you so much! It worked.

                    1 Reply Last reply
                    0
                    • A andreyc
                      17 Oct 2014, 17:52

                      Are you talking about something like this
                      @
                      void Widget::on_pushButton_clicked()
                      {
                      if (m_hiddenWidget) {
                      ui->tabWidget->insertTab(m_hiddenIndex, m_hiddenWidget, m_hiddenLabel);
                      m_hiddenWidget = nullptr;
                      ui->pushButton->setText("Hide");
                      } else {
                      m_hiddenWidget = ui->tabWidget->currentWidget();
                      m_hiddenIndex = ui->tabWidget->indexOf(m_hiddenWidget);
                      m_hiddenLabel = ui->tabWidget->tabText(m_hiddenIndex);
                      ui->tabWidget->removeTab(m_hiddenIndex);
                      ui->pushButton->setText("Show");
                      }
                      }
                      @

                      A Offline
                      A Offline
                      amarism
                      wrote on 18 May 2018, 07:23 last edited by
                      #10

                      @andreycI am not understood. whats m_hiddenWidget,m_hiddenIndex and m_hiddenLabel

                      1 Reply Last reply
                      0
                      • A andreyc
                        17 Oct 2014, 17:52

                        Are you talking about something like this
                        @
                        void Widget::on_pushButton_clicked()
                        {
                        if (m_hiddenWidget) {
                        ui->tabWidget->insertTab(m_hiddenIndex, m_hiddenWidget, m_hiddenLabel);
                        m_hiddenWidget = nullptr;
                        ui->pushButton->setText("Hide");
                        } else {
                        m_hiddenWidget = ui->tabWidget->currentWidget();
                        m_hiddenIndex = ui->tabWidget->indexOf(m_hiddenWidget);
                        m_hiddenLabel = ui->tabWidget->tabText(m_hiddenIndex);
                        ui->tabWidget->removeTab(m_hiddenIndex);
                        ui->pushButton->setText("Show");
                        }
                        }
                        @

                        N Offline
                        N Offline
                        Nguyen Minh Tri
                        wrote on 4 Mar 2019, 06:50 last edited by
                        #11

                        @andreyc It work very well, thank you so much.

                        1 Reply Last reply
                        0

                        • Login

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