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. Hiding the TabWidget
Forum Updated to NodeBB v4.3 + New Features

Hiding the TabWidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
24 Posts 4 Posters 8.3k 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.
  • A amarism

    Hi,

    I am using QtCreator and have implemented a QTabWidget on my MainWindow. With the designer, I have 2 tabs that all include ListWidget and other labels. I would like to hide and show specific tabs with respect to what the user selects.

    Thanks.

    mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #2

    @amarism

    Hi
    You cannot hide them as such.
    You can use removeTab() and addTab()
    and keep the QWidget * around ( the tab)
    so you take them out to be hidden and put in to be visible.

    A 2 Replies Last reply
    1
    • mrjjM mrjj

      @amarism

      Hi
      You cannot hide them as such.
      You can use removeTab() and addTab()
      and keep the QWidget * around ( the tab)
      so you take them out to be hidden and put in to be visible.

      A Offline
      A Offline
      amarism
      wrote on last edited by
      #3

      @mrjj do u have a piece of code. I getting very confused

      JonBJ 1 Reply Last reply
      0
      • A amarism

        @mrjj do u have a piece of code. I getting very confused

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by
        #4

        @amarism
        There is example code in a post in this forum, https://forum.qt.io/topic/47139/solved-hide-and-show-a-qtabwidget-tab, showing insertTab/removeTab() example?

        1 Reply Last reply
        1
        • mrjjM mrjj

          @amarism

          Hi
          You cannot hide them as such.
          You can use removeTab() and addTab()
          and keep the QWidget * around ( the tab)
          so you take them out to be hidden and put in to be visible.

          A Offline
          A Offline
          amarism
          wrote on last edited by
          #5

          @mrjj addItem is not a member for QTabWIdget

          mrjjM JonBJ 2 Replies Last reply
          0
          • A amarism

            @mrjj addItem is not a member for QTabWIdget

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #6

            @amarism
            No, as its not addItem but
            http://doc.qt.io/qt-5/qtabwidget.html#addTab

            1 Reply Last reply
            1
            • A amarism

              @mrjj addItem is not a member for QTabWIdget

              JonBJ Online
              JonBJ Online
              JonB
              wrote on last edited by
              #7

              @amarism
              You're saying all you want is to hide a tab on the tabbar, so that the user cannot see or click it, right?

              If the addTab/removeTab is all too much for you, you might try leveraging:

              Most of the functionality in QTabWidget is provided by a QTabBar (at the top, providing the tabs) and a QStackedWidget (most of the area, organizing the individual pages).

              http://doc.qt.io/qt-5/qtabwidget.html#tabBar returns the QTabBar, and from there you could try making the desired tab an empty widget or a hidden one (e.g. setStylesheet with display: "none";) or something? It's food for thought.

              BTW, if you are satisfied with disabling the tab instead of actually hiding it, there is always the simple http://doc.qt.io/qt-5/qtabwidget.html#setTabEnabled.

              A 1 Reply Last reply
              0
              • J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by
                #8

                Here a basic example:

                //header of your class, you need at least a QString and a QWidget pointer as member variables
                
                {
                .....
                private:
                    QWidget *removedWidget = Q_NULLPTR;
                    QString removedTabString;
                }
                
                //cpp part of your class, this creates a QTabwidget, populates it with 3 tabs, and uses remove and addTab to move the first tab to the end
                
                QTabWidget *tWidget = new QTabWidget(this);
                    tWidget->show();
                    tWidget->addTab(new QWidget(), "Tab1");
                    tWidget->addTab(new QWidget(), "Tab2");
                    tWidget->addTab(new QWidget(), "Tab3");
                
                
                    //The following lines will take Tab1, remove it/store it and add it back to the tabwidget at the last position
                
                
                    //remove Tab and 'save' it in a member variable, its not really saved, but you store a pointer to it
                    if(removedWidget == Q_NULLPTR){
                        //Pointer is empty tab can be "stored"
                
                        //Save Tab text
                        removedTabString = tWidget->tabText(0);
                
                        //'Save' actual widget
                        removedWidget = tWidget->widget(0);
                
                        //Remove from QTabWidget
                        tWidget->removeTab(0);
                    }
                
                    //Add Tab to widget
                    if( removedWidget != Q_NULLPTR){
                        //The pointer actually points to a valid previously removed tab
                        tWidget->addTab(removedWidget, removedTabString);
                
                        //set pointer back to 0 to free it for potential next operation
                        removedWidget = Q_NULLPTR;
                    }
                

                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                A 1 Reply Last reply
                0
                • JonBJ JonB

                  @amarism
                  You're saying all you want is to hide a tab on the tabbar, so that the user cannot see or click it, right?

                  If the addTab/removeTab is all too much for you, you might try leveraging:

                  Most of the functionality in QTabWidget is provided by a QTabBar (at the top, providing the tabs) and a QStackedWidget (most of the area, organizing the individual pages).

                  http://doc.qt.io/qt-5/qtabwidget.html#tabBar returns the QTabBar, and from there you could try making the desired tab an empty widget or a hidden one (e.g. setStylesheet with display: "none";) or something? It's food for thought.

                  BTW, if you are satisfied with disabling the tab instead of actually hiding it, there is always the simple http://doc.qt.io/qt-5/qtabwidget.html#setTabEnabled.

                  A Offline
                  A Offline
                  amarism
                  wrote on last edited by amarism
                  #9

                  @JonB !0_1526634287201_tw.png
                  no, it's not like that people only see the tab name but after clicking he will see inside anything just like visual studio example.
                  I want to make my code for mention image. Where I will make 2 black round image when I will click this it will pop out.
                  0_1526634459438_tw.png.
                  Last I need to get 2nd one type output

                  1 Reply Last reply
                  0
                  • J.HilkJ J.Hilk

                    Here a basic example:

                    //header of your class, you need at least a QString and a QWidget pointer as member variables
                    
                    {
                    .....
                    private:
                        QWidget *removedWidget = Q_NULLPTR;
                        QString removedTabString;
                    }
                    
                    //cpp part of your class, this creates a QTabwidget, populates it with 3 tabs, and uses remove and addTab to move the first tab to the end
                    
                    QTabWidget *tWidget = new QTabWidget(this);
                        tWidget->show();
                        tWidget->addTab(new QWidget(), "Tab1");
                        tWidget->addTab(new QWidget(), "Tab2");
                        tWidget->addTab(new QWidget(), "Tab3");
                    
                    
                        //The following lines will take Tab1, remove it/store it and add it back to the tabwidget at the last position
                    
                    
                        //remove Tab and 'save' it in a member variable, its not really saved, but you store a pointer to it
                        if(removedWidget == Q_NULLPTR){
                            //Pointer is empty tab can be "stored"
                    
                            //Save Tab text
                            removedTabString = tWidget->tabText(0);
                    
                            //'Save' actual widget
                            removedWidget = tWidget->widget(0);
                    
                            //Remove from QTabWidget
                            tWidget->removeTab(0);
                        }
                    
                        //Add Tab to widget
                        if( removedWidget != Q_NULLPTR){
                            //The pointer actually points to a valid previously removed tab
                            tWidget->addTab(removedWidget, removedTabString);
                    
                            //set pointer back to 0 to free it for potential next operation
                            removedWidget = Q_NULLPTR;
                        }
                    
                    A Offline
                    A Offline
                    amarism
                    wrote on last edited by
                    #10

                    @J.Hilk This code not hiding the tab, only increase the tab when we click on tab bar

                    J.HilkJ 1 Reply Last reply
                    0
                    • A amarism

                      @J.Hilk This code not hiding the tab, only increase the tab when we click on tab bar

                      J.HilkJ Offline
                      J.HilkJ Offline
                      J.Hilk
                      Moderators
                      wrote on last edited by
                      #11

                      @amarism did you read the comments of the code example?


                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                      Q: What's that?
                      A: It's blue light.
                      Q: What does it do?
                      A: It turns blue.

                      A 1 Reply Last reply
                      0
                      • J.HilkJ J.Hilk

                        @amarism did you read the comments of the code example?

                        A Offline
                        A Offline
                        amarism
                        wrote on last edited by
                        #12

                        @J.Hilk Still am not able to complete my task

                        1 Reply Last reply
                        0
                        • mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #13

                          Hi
                          What is not working ?
                          How does your current code look ?

                          A 1 Reply Last reply
                          0
                          • mrjjM mrjj

                            Hi
                            What is not working ?
                            How does your current code look ?

                            A Offline
                            A Offline
                            amarism
                            wrote on last edited by amarism
                            #14

                            @mrjj 0_1526884364537_TTTTTT.png

                            I want to hide and show tab 1 and tab 2 by clicking on tab1 and tab 2. But when I used ur code they adding the extra tab on another side.

                            1 Reply Last reply
                            0
                            • mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by mrjj
                              #15

                              Hi
                              So you have 2 tabwidgets?
                              Since its impossible to click on hidden tab as its not there. so you could never unhide it again with clicking.

                              So when user click on tab 1 on tabWidget1, you want tab 1 to be shown on tabwidget 2?

                              else i dont get what you are trying as the tab will be COMPLETELY gone if u "hide" it and hence you cannot click on it again
                              so some other means of showing it is needed.

                              Or did you just use @J-Hilk code as it is and got a second widget as it does
                              QTabWidget *tWidget = new QTabWidget(this);
                              ??
                              If you are using that code with UI then
                              QTabWidget *tWidget = ui->yourtabwidget as else you will create a second one.

                              A 1 Reply Last reply
                              0
                              • mrjjM mrjj

                                Hi
                                So you have 2 tabwidgets?
                                Since its impossible to click on hidden tab as its not there. so you could never unhide it again with clicking.

                                So when user click on tab 1 on tabWidget1, you want tab 1 to be shown on tabwidget 2?

                                else i dont get what you are trying as the tab will be COMPLETELY gone if u "hide" it and hence you cannot click on it again
                                so some other means of showing it is needed.

                                Or did you just use @J-Hilk code as it is and got a second widget as it does
                                QTabWidget *tWidget = new QTabWidget(this);
                                ??
                                If you are using that code with UI then
                                QTabWidget *tWidget = ui->yourtabwidget as else you will create a second one.

                                A Offline
                                A Offline
                                amarism
                                wrote on last edited by amarism
                                #16

                                @mrjj hide means the content of the tab hides not tab1 & tab2 hide just like a visual studio. ie I will be uploaded in the previously. Just see the example

                                mrjjM 1 Reply Last reply
                                0
                                • A amarism

                                  @mrjj hide means the content of the tab hides not tab1 & tab2 hide just like a visual studio. ie I will be uploaded in the previously. Just see the example

                                  mrjjM Offline
                                  mrjjM Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on last edited by mrjj
                                  #17

                                  @amarism
                                  so you want to hide what INSIDE the tab and not the actual tab?

                                  I dont know how Visual studio tabs works.
                                  But in Qt the tab is the whole white area and it will always show regardless of what you put inside.

                                  But if you just want to hide the content of the tab, why you ask how to remove / insert tabs.
                                  It sounds like u just want to hide ListWidget or what you have inside and not the "Tab 1"

                                  A 1 Reply Last reply
                                  0
                                  • mrjjM mrjj

                                    @amarism
                                    so you want to hide what INSIDE the tab and not the actual tab?

                                    I dont know how Visual studio tabs works.
                                    But in Qt the tab is the whole white area and it will always show regardless of what you put inside.

                                    But if you just want to hide the content of the tab, why you ask how to remove / insert tabs.
                                    It sounds like u just want to hide ListWidget or what you have inside and not the "Tab 1"

                                    A Offline
                                    A Offline
                                    amarism
                                    wrote on last edited by
                                    #18

                                    @mrjj Now how to resolve this problem.

                                    mrjjM 1 Reply Last reply
                                    0
                                    • A amarism

                                      @mrjj Now how to resolve this problem.

                                      mrjjM Offline
                                      mrjjM Offline
                                      mrjj
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #19

                                      @amarism

                                      Im still not sure what you are trying but if just to hide/show say ListWidget
                                      you can simply use
                                      ui->listwidget->show();
                                      and
                                      ui->listwidget->hide();

                                      A 1 Reply Last reply
                                      0
                                      • mrjjM mrjj

                                        @amarism

                                        Im still not sure what you are trying but if just to hide/show say ListWidget
                                        you can simply use
                                        ui->listwidget->show();
                                        and
                                        ui->listwidget->hide();

                                        A Offline
                                        A Offline
                                        amarism
                                        wrote on last edited by amarism
                                        #20

                                        @mrjj I will try this one but when Clicking the Tab then inside the also hide and next we can't show hiding tab

                                        mrjjM 1 Reply Last reply
                                        0
                                        • A amarism

                                          @mrjj I will try this one but when Clicking the Tab then inside the also hide and next we can't show hiding tab

                                          mrjjM Offline
                                          mrjjM Offline
                                          mrjj
                                          Lifetime Qt Champion
                                          wrote on last edited by
                                          #21

                                          @amarism said in Hiding the TabWidget:

                                          when hiding the Tab widget next we can't show hiding tab

                                          Im not sure what that means. If you hide tabWidget, all tabs will be hidden.

                                          A 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