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. HBoxlayout items starting on the left?

HBoxlayout items starting on the left?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 534 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.
  • J Offline
    J Offline
    jkwok678
    wrote on last edited by
    #1

    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

    jsulmJ 1 Reply Last reply
    0
    • J jkwok678

      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

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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
      2
      • J Offline
        J Offline
        jkwok678
        wrote on last edited by
        #3

        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
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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
          0
          • J Offline
            J Offline
            jkwok678
            wrote on last edited by
            #5

            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
            0
            • J jkwok678

              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 Offline
              B Offline
              Bonnie
              wrote on last edited by
              #6

              @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
              2
              • J Offline
                J Offline
                jkwok678
                wrote on last edited by
                #7

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

                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