Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Forum Updated on Feb 6th

    Adding button to QTabWidget tabs

    General and Desktop
    5
    11
    22320
    Loading More Posts
    • 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
      thehilmisu last edited by

      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 Reply Quote 1
      • T
        tilsitt last edited by

        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 Reply Quote 1
        • T
          thehilmisu last edited by

          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 Reply Quote 0
          • T
            tilsitt last edited by

            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 Reply Quote 1
            • T
              thehilmisu last edited by

              Let me explain it with this picture

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

              1 Reply Last reply Reply Quote 0
              • T
                tilsitt last edited by

                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 Reply Quote 2
                • L
                  lgeyer last edited by

                  Nevermind.

                  1 Reply Last reply Reply Quote 0
                  • T
                    thehilmisu last edited by

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

                    1 Reply Last reply Reply Quote 0
                    • S
                      SherifOmran last edited by

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

                      1 Reply Last reply Reply Quote 0
                      • W
                        WhiteNight last edited by

                        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 Reply Quote 0
                        • W
                          WhiteNight @thehilmisu last edited by

                          @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 Reply Quote 0
                          • First post
                            Last post