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]Strange widget positioning within a QToolBar
Forum Updated to NodeBB v4.3 + New Features

[solved]Strange widget positioning within a QToolBar

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 4.9k 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.
  • J Offline
    J Offline
    JulienMaille
    wrote on last edited by
    #1

    I have a problem with adding 3 widgets arranged in a QGridLayout.
    It works when I insert this into a QToolbar that I have defined with designer.
    I fails when this QToolbar is defined within the code. @QToolBar* uiToolbar = new QToolBar(mainWindow);

    QWidget *w = new QWidget;
    QGridLayout *gbox = new QGridLayout;

    QComboBox* parametersCB = new QComboBox;
    QLabel* typeLabel = new QLabel("type");
    QLabel* currentLabel = new QLabel(tr("Current parameters:"));

    gbox->addWidget(currentLabel,0,0,1,2);
    gbox->addWidget(parametersCB,1,0);
    gbox->addWidget(typeLabel,1,1);

    w->setLayout(gbox);
    uiToolbar->addWidget(w);
    mainWindow->addToolBar(Qt::TopToolBarArea, uiToolbar);@ I get this !http://i.imgur.com/uDNAY.png!
    And after moving it one widget is on top of another one:!http://i.imgur.com/PpI8c.png!
    The same with a pre existing toolbar:
    @preExistingToolbar->addWidget(w);@ Perfect: !http://i.imgur.com/L2mPp.png!

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      QMartin
      wrote on last edited by
      #2

      Hello Julien!

      I've tried your code and it works fine. I've done it subclassing a QMainWindow and directly from a main.cpp defining a basic QMainWindow. From both I obtained your desired form. Cannot find where the problem could be. Maybe I didn't understand your problem.

      @#include <QtGui>
      #include <QApplication>

      int main(int argc, char *argv[])
      {
      QApplication app(argc, argv);
      QMainWindow *mainWindow = new QMainWindow();

      QToolBar* uiToolbar = new QToolBar(mainWindow);
       
      QWidget *w = new QWidget;
      QGridLayout *gbox = new QGridLayout;
       
      QComboBox* parametersCB = new QComboBox;
      QLabel* typeLabel = new QLabel("type");
      QLabel* currentLabel = new QLabel("Current parameters:");
       
      gbox->addWidget(currentLabel,0,0,1,2);
      gbox->addWidget(parametersCB,1,0);
      gbox->addWidget(typeLabel,1,1);
       
      w->setLayout(gbox);
      uiToolbar->addWidget(w);
      mainWindow->addToolBar(Qt::TopToolBarArea, uiToolbar);
      
      mainWindow->show();
      
      return app.exec();
      

      }@

      Could you give more details?

      Regards

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JulienMaille
        wrote on last edited by
        #3

        First, thanks a lot for your time!
        Can you post a screenshot of the result?
        That is really weird, something in my code must be interacting with the layout, but I have no idea what it is.

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          QMartin
          wrote on last edited by
          #4

          Of course. But I don't know how to post a picture here, it asks me for some source. How did you managed to do it? O.o

          1 Reply Last reply
          0
          • J Offline
            J Offline
            JulienMaille
            wrote on last edited by
            #5

            use http://imgur.com/

            1 Reply Last reply
            0
            • Q Offline
              Q Offline
              QMartin
              wrote on last edited by
              #6

              Ok, thanks!

              Here you are !http://i.imgur.com/flPRn.png?1(image1)!

              1 Reply Last reply
              0
              • U Offline
                U Offline
                utcenter
                wrote on last edited by
                #7

                Or simply put the combo box and the type label in a new horizontal layout that is added after the first label in a vertical layout. I actually prefer that to setting up a grid layout.

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  JulienMaille
                  wrote on last edited by
                  #8

                  There must be something broken in my toolbar. How can I easily debug that?

                  1 Reply Last reply
                  0
                  • Q Offline
                    Q Offline
                    QMartin
                    wrote on last edited by
                    #9

                    Hello again!

                    Select a debug build and introduce break points wherever you want/need. Look anywhere you are accessing the toolbar. If you cannot find the problem just proceed as utcenter said:

                    bq. put the combo box and the type label in a new horizontal layout that is added after the first label in a vertical layout

                    Sometimes this method simplifies your life.

                    Good luck!

                    1 Reply Last reply
                    0
                    • J Offline
                      J Offline
                      JulienMaille
                      wrote on last edited by
                      #10

                      That solved it! Thanks again.

                      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