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. Adding button to QTabWidget tabs

Adding button to QTabWidget tabs

Scheduled Pinned Locked Moved General and Desktop
11 Posts 5 Posters 25.3k 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.
  • T Offline
    T Offline
    thehilmisu
    wrote on last edited by
    #1

    Hi everyone,
    I have created a QTabWidget and it's tab count changing dynamically when a signal is triggerd. I have add tabs like

    @
    QWidget *centralWidget = new QWidget();
    ui->tabWidget->addTab(centralWidget,client->peerAddress().toString());
    @
    Everything is okey by now, but the problem is i want to add button to this tabs/centralWidget.

    Is there anyway to do it?

    Thanks in advance.

    W 1 Reply Last reply
    1
    • T Offline
      T Offline
      tilsitt
      wrote on last edited by
      #2

      Hi,

      if you want to add a button on a specific tab (e.g. a close tab button), you can use "setTabButton()":http://qt-project.org/doc/qt-4.8/qtabbar.html#setTabButton on the tab bar.

      if you want to add a button to the tab widget itself (e.g. an add tab button), I think "setCornerWidget()":http://qt-project.org/doc/qt-4.8/qtabwidget.html#setCornerWidget is what you are searching.

      1 Reply Last reply
      1
      • T Offline
        T Offline
        thehilmisu
        wrote on last edited by
        #3

        Both "setTabButton()" and "setCornerWidget()" is not what i want. I want that button to inside the "tab" not the tab header section. In the tab. For example, I have 5 tabs and i select the third tab, i want to see this button inside this particular tab.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tilsitt
          wrote on last edited by
          #4

          You mean something like that:

          @
          class MyPage : public QWidget
          {
          void addButton(QPushButton* button);
          void setContents(QWidget* widget);
          };

          MyPage *page = new MyPage;
          QWidget *centralWidget = new QWidget;

          page->setContents(centralWidget);
          page->addButton(new QPushButton);

          ui->tabWidget->addTab(page, ,client->peerAddress().toString());
          @

          1 Reply Last reply
          1
          • T Offline
            T Offline
            thehilmisu
            wrote on last edited by
            #5

            Let me explain it with this picture

            !http://s9.postimage.org/mnp87snfj/Untitled.png()!

            1 Reply Last reply
            0
            • T Offline
              T Offline
              tilsitt
              wrote on last edited by
              #6

              Ok. That's what I tried to say with my piece of code :)

              So you just have to create a base class for all your tabs, like the one in my previous post.

              If you want to force your QTabWidget to use it only, you will have to sub-class QTabWidget.

              1 Reply Last reply
              2
              • L Offline
                L Offline
                lgeyer
                wrote on last edited by
                #7

                Nevermind.

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  thehilmisu
                  wrote on last edited by
                  #8

                  Thank you tilsitt !
                  I am going to try it and post the result.

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SherifOmran
                    wrote on last edited by
                    #9

                    In the GUI right click QTabWidget and select add page :)

                    1 Reply Last reply
                    0
                    • W Offline
                      W Offline
                      WhiteNight
                      wrote on last edited by
                      #10

                      Dear Thehillmisu,
                      I have the same problem. I would like to add a QChart to a tab in tabWidget. I came so long that I can show it in main window using following but I don't know how to access to the tabWidget itself:

                      ui->setupUi(this);
                      this->setCentralWidget(chartView);

                      Thanks in advance!

                      1 Reply Last reply
                      0
                      • T thehilmisu

                        Hi everyone,
                        I have created a QTabWidget and it's tab count changing dynamically when a signal is triggerd. I have add tabs like

                        @
                        QWidget *centralWidget = new QWidget();
                        ui->tabWidget->addTab(centralWidget,client->peerAddress().toString());
                        @
                        Everything is okey by now, but the problem is i want to add button to this tabs/centralWidget.

                        Is there anyway to do it?

                        Thanks in advance.

                        W Offline
                        W Offline
                        WhiteNight
                        wrote on last edited by
                        #11

                        @thehilmisu

                        Dear Thehillmisu,
                        I have the same problem. I would like to add a QChart to a tab in tabWidget. I came so long that I can show it in main window using following but I don't know how to access to the tabWidget itself:

                        ui->setupUi(this);
                        this->setCentralWidget(chartView);

                        Thanks in advance!

                        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