Qt Forum

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

    Unsolved HBoxlayout items starting on the left?

    General and Desktop
    4
    7
    149
    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.
    • J
      jkwok678 last edited by

      I've been trying to use the HBoxlayout and I'm trying to get all the QToolButtons to start and clump on the left hand side (unlike the screenshot). I've been adding them to the HBoxLayout with Qt::alignLeft. What am I doing wrong?

       QTextBrowser *centralWidget = new QTextBrowser;
          centralWidget->setPlainText(tr("Central widget"));
      
          BorderLayout *layout = new BorderLayout;
      
          QWidget *menu = new QWidget();
          QVBoxLayout *vboxLayout = new QVBoxLayout();
          QWidget *menu1 = new QWidget();
          vboxLayout->addWidget(menu1);
          QHBoxLayout *hboxLayout = new QHBoxLayout();
          QToolButton *b1 = new QToolButton();
          QToolButton *b2 = new QToolButton();
          hboxLayout->addWidget(b1,Qt::AlignLeft);
          hboxLayout->addWidget(b2,Qt::AlignLeft);
          menu1->setLayout(hboxLayout);
          menu->setLayout(vboxLayout);
      
          QPalette pal = palette();
          // set black background
          pal.setColor(QPalette::Window, Qt::black);
          menu->setAutoFillBackground(true);
          menu->setPalette(pal);
      
          QPalette pal2 = palette();
          // set dark red background
          pal2.setColor(QPalette::Window, Qt::darkRed);
          menu1->setAutoFillBackground(true);
          menu1->setPalette(pal2);
      
      
      
          layout->addWidget(centralWidget, BorderLayout::Center);
          layout->addWidget(menu, BorderLayout::North);
          layout->addWidget(createLabel("West"), BorderLayout::West);
          layout->addWidget(createLabel("East 1"), BorderLayout::East);
          layout->addWidget(createLabel("East 2") , BorderLayout::East);
          layout->addWidget(createLabel("South"), BorderLayout::South);
          setLayout(layout);
      
          setWindowTitle(tr("Border Layout"));
      

      hbox align issue.png

      jsulm 1 Reply Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion @jkwok678 last edited by

        @jkwok678 Take a look at https://doc.qt.io/qt-5/qspaceritem.html
        Especially "QHBoxLayout addSpacing(), addStretch(), insertSpacing(), insertStretch()"

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 2
        • J
          jkwok678 last edited by

          I'm just wondering if this is the only way to do it? Is there a more elegant way to do it so that it can work with a GUI that changes when the window changes size?

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            Hi,

            What changes do you have in mind ?

            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 Reply Quote 0
            • J
              jkwok678 last edited by

              For example what happens with the spacers, when the window size isn't big enough to justify them being there, as in it distorts the other elements in the GUI?

              B 1 Reply Last reply Reply Quote 0
              • B
                Bonnie @jkwok678 last edited by

                @jkwok678
                The spacers are just suitable for a changing window size.
                When there's no enough space, their size will shrink to zero.

                1 Reply Last reply Reply Quote 2
                • J
                  jkwok678 last edited by

                  So I'm just wondering is there any point using Qt::Align___?

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post