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. Can not control the position of a QToolbar within a QTabWidget
Qt 6.12 LTS is out! See what's new in the release blog

Can not control the position of a QToolbar within a QTabWidget

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 3 Posters 5.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.
  • cheopsC Offline
    cheopsC Offline
    cheops
    wrote on last edited by
    #1

    Hi guys,

    I have a, maybe for most of you really stupid, question, but I'm thinking about that for the last five hours, including a lot of asking Dr. Google, but I was not able to find a solution... :-(

    I try to place a QToolbar within a QTabWidget (this is because within the tabs different kinds of widgets will run, both 3D and 2D representation of models, which will need different edit and filtering functions, which I want to place as near as possible to the graphical representation of the data). Basicaly it works, but the QToolbar ist located on the bottom of the widget, and I want it on the top...

    Following the relevant parts of my code:

    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        // Setup GUI with application name and version
        ui->setupUi(this);
        QString windowTitle = applicationName + " " + version;
        this->setWindowTitle (windowTitle);
    
        // Create new toolbar for Cloud Viewer tab widget
        QToolBar *cloudViewerToolbar = new QToolBar;
    
        // Create actions for the Cloud Viewer toolbar
        QAction *actionFitToScreen = new QAction(QIcon(":/view/fit"),tr("Fit to screen"), this);
    
        // Add actions to Cloud Viewer toolbar
        cloudViewerToolbar->addAction(actionFitToScreen);
        
        // Add toolbar to Cloud Viewer tab widget
        ui->tabCloudViewer->layout()->addWidget(cloudViewerToolbar);
        
        // Connect actions for Cloud Viewer toolbar with slots
        connect(actionFitToScreen, SIGNAL(triggered()), this, SLOT(on_actionFit_to_screen_triggered()));
    
        // Set up the QVTK Cloud Viewer widget
        viewer.reset (new pcl::visualization::PCLVisualizer ("viewer", false));
        ui->qvtkWidget->SetRenderWindow (viewer->getRenderWindow ());
        viewer->setupInteractor (ui->qvtkWidget->GetInteractor (), ui->qvtkWidget->GetRenderWindow ());
        MainWindow::updateViewerColors();
        ui->qvtkWidget->update ();
    }
    

    As mentioned, this code works, my only problem ist the positioning of the QToolbar on the bottom of the tab widget...

    Can someone tell me, what I do not understand and point me to the right direction?

    Thanks in advance,
    Vittorio

    JonBJ 1 Reply Last reply
    0
    • cheopsC cheops

      Hi guys,

      I have a, maybe for most of you really stupid, question, but I'm thinking about that for the last five hours, including a lot of asking Dr. Google, but I was not able to find a solution... :-(

      I try to place a QToolbar within a QTabWidget (this is because within the tabs different kinds of widgets will run, both 3D and 2D representation of models, which will need different edit and filtering functions, which I want to place as near as possible to the graphical representation of the data). Basicaly it works, but the QToolbar ist located on the bottom of the widget, and I want it on the top...

      Following the relevant parts of my code:

      MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow)
      {
          // Setup GUI with application name and version
          ui->setupUi(this);
          QString windowTitle = applicationName + " " + version;
          this->setWindowTitle (windowTitle);
      
          // Create new toolbar for Cloud Viewer tab widget
          QToolBar *cloudViewerToolbar = new QToolBar;
      
          // Create actions for the Cloud Viewer toolbar
          QAction *actionFitToScreen = new QAction(QIcon(":/view/fit"),tr("Fit to screen"), this);
      
          // Add actions to Cloud Viewer toolbar
          cloudViewerToolbar->addAction(actionFitToScreen);
          
          // Add toolbar to Cloud Viewer tab widget
          ui->tabCloudViewer->layout()->addWidget(cloudViewerToolbar);
          
          // Connect actions for Cloud Viewer toolbar with slots
          connect(actionFitToScreen, SIGNAL(triggered()), this, SLOT(on_actionFit_to_screen_triggered()));
      
          // Set up the QVTK Cloud Viewer widget
          viewer.reset (new pcl::visualization::PCLVisualizer ("viewer", false));
          ui->qvtkWidget->SetRenderWindow (viewer->getRenderWindow ());
          viewer->setupInteractor (ui->qvtkWidget->GetInteractor (), ui->qvtkWidget->GetRenderWindow ());
          MainWindow::updateViewerColors();
          ui->qvtkWidget->update ();
      }
      

      As mentioned, this code works, my only problem ist the positioning of the QToolbar on the bottom of the tab widget...

      Can someone tell me, what I do not understand and point me to the right direction?

      Thanks in advance,
      Vittorio

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @cheops
      To be clear: You wish to add a single QToolbar onto a QTabWidget as a whole, not on each page. You will presumably be putting tab-pages on the QTabWidget, but your code does not do that yet. You have added the toolbar and can tell it will come at the bottom of the tab-pages, but you want above the tabs. Is that correct?

      cheopsC 1 Reply Last reply
      0
      • JonBJ JonB

        @cheops
        To be clear: You wish to add a single QToolbar onto a QTabWidget as a whole, not on each page. You will presumably be putting tab-pages on the QTabWidget, but your code does not do that yet. You have added the toolbar and can tell it will come at the bottom of the tab-pages, but you want above the tabs. Is that correct?

        cheopsC Offline
        cheopsC Offline
        cheops
        wrote on last edited by
        #3

        @JNBarchan

        Hi,

        thanks for your reply! I hope, I inderstand what you mean... no, I want to add a different QToolbar on each page of the tab widget! This seems to be no problem, the only thing I'm fighting with is, that the toolbar appears on the bottom of the tab page...

        In my example I have two tabs, one for 3D-models and one for pictures. I need different filters and editing functions for this two tabs, that's why I want two show differene toolbars in the tabs...

        Greetings,
        VIttorio

        JonBJ 1 Reply Last reply
        0
        • cheopsC cheops

          @JNBarchan

          Hi,

          thanks for your reply! I hope, I inderstand what you mean... no, I want to add a different QToolbar on each page of the tab widget! This seems to be no problem, the only thing I'm fighting with is, that the toolbar appears on the bottom of the tab page...

          In my example I have two tabs, one for 3D-models and one for pictures. I need different filters and editing functions for this two tabs, that's why I want two show differene toolbars in the tabs...

          Greetings,
          VIttorio

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

          @cheops

          I try to place a QToolbar within a QTabWidget

          // Add toolbar to Cloud Viewer tab widget
          ui->tabCloudViewer->layout()->addWidget(cloudViewerToolbar);
          

          I take these statements to indicate that ui->tabCloudViewer is the QTabWidget. Are you saying it is a page-widget on the QTabWidget? What type is it?

          cheopsC 1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            Except that you are currently adding that toolbar under your QTabWidget and not at the bottom of the widget inside the tab.

            Since you want different tabs to have different tool bars, you should consider making a base "tab widget" class that contains what you need and that you can configure.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            cheopsC 1 Reply Last reply
            0
            • JonBJ JonB

              @cheops

              I try to place a QToolbar within a QTabWidget

              // Add toolbar to Cloud Viewer tab widget
              ui->tabCloudViewer->layout()->addWidget(cloudViewerToolbar);
              

              I take these statements to indicate that ui->tabCloudViewer is the QTabWidget. Are you saying it is a page-widget on the QTabWidget? What type is it?

              cheopsC Offline
              cheopsC Offline
              cheops
              wrote on last edited by
              #6

              @JNBarchan
              No, ui->tabCloudViewer is a page on a QTabWidget with the name tabWidget...

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                OK, thanks for the clarification.

                In that case, you can use insertWidget so you can prepend the toolbar.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • SGaistS SGaist

                  Hi,

                  Except that you are currently adding that toolbar under your QTabWidget and not at the bottom of the widget inside the tab.

                  Since you want different tabs to have different tool bars, you should consider making a base "tab widget" class that contains what you need and that you can configure.

                  cheopsC Offline
                  cheopsC Offline
                  cheops
                  wrote on last edited by
                  #8

                  @SGaist

                  Hi,
                  my problem ist, that I'm not able to configure the tab widget in a way, that the toolbar appears at the top of the tab page... So to create a new class wouldnt change anything, because I would also in such a case not be able to configure the tab page in the way I want...

                  Or am I completely wrong?

                  JonBJ 1 Reply Last reply
                  0
                  • cheopsC cheops

                    @SGaist

                    Hi,
                    my problem ist, that I'm not able to configure the tab widget in a way, that the toolbar appears at the top of the tab page... So to create a new class wouldnt change anything, because I would also in such a case not be able to configure the tab page in the way I want...

                    Or am I completely wrong?

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #9

                    @cheops
                    @SGaist is telling you that you can have the toolbar at the top:

                    // Add toolbar to Cloud Viewer tab widget
                    ui->tabCloudViewer->layout()->addWidget(cloudViewerToolbar);
                    

                    Use insertWidget instead of addWidget. addWidget always adds at end.

                    cheopsC 1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      The widget you should have as tab should basically be:

                      • A QWidget with
                      • A QVBoxLayout and
                      • Your VTK widget inside that layout.

                      And in that case you can insert the QToolBar as proposed.

                      Or you can make a custom widget with the same content plus a method that would handle adding/setting a QToolBar in that tab.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • JonBJ JonB

                        @cheops
                        @SGaist is telling you that you can have the toolbar at the top:

                        // Add toolbar to Cloud Viewer tab widget
                        ui->tabCloudViewer->layout()->addWidget(cloudViewerToolbar);
                        

                        Use insertWidget instead of addWidget. addWidget always adds at end.

                        cheopsC Offline
                        cheopsC Offline
                        cheops
                        wrote on last edited by
                        #11

                        @JNBarchan Class QLayout has no member insertWidget?

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          QBoxLayout::insertWidget. QBoxLayout is the base class of QVBoxLayout and QHBoxLayout.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          cheopsC 1 Reply Last reply
                          1
                          • SGaistS SGaist

                            QBoxLayout::insertWidget. QBoxLayout is the base class of QVBoxLayout and QHBoxLayout.

                            cheopsC Offline
                            cheopsC Offline
                            cheops
                            wrote on last edited by
                            #13

                            @SGaist
                            I tried to create a new widget class based on MainWindow, where I can configure all things I need very easy in QtDesigner, and I can easily insert this widget with

                            cloudViewer *cv = new cloudViewer;
                            ui->tabWidget->addTab(cv, "3D Viewer");
                            

                            ... I think, this is the simplest way for my needs, or is there somthing wrong with this solution in you opinion?

                            1 Reply Last reply
                            0
                            • SGaistS Offline
                              SGaistS Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              I don't see anything particularly wrong here.

                              Interested in AI ? www.idiap.ch
                              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                              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
                              • Unsolved