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. Align buttons on the right side of QHBoxLayout.
QtWS25 Last Chance

Align buttons on the right side of QHBoxLayout.

Scheduled Pinned Locked Moved Unsolved General and Desktop
qhboxlayoutqlayout
5 Posts 4 Posters 14.1k 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.
  • T Offline
    T Offline
    tokafr
    wrote on 9 Mar 2016, 10:33 last edited by
    #1

    Hello!
    I need to place buttons on the horizontal layout, I have several buttons, one I want to put on the left size of layout and the rest on the right side. So I do

    //your code here

      lButtonLayout_ -> insertWidget(0, homeButton_);
      lButtonLayout_ -> insertWidget(1, backButton_);
      lButtonLayout_ -> insertWidget(2, addButton_);
      lButtonLayout_ -> insertWidget(3, removeButton_);
      lButtonLayout_ -> insertWidget(4, refreshButton_);
      lButtonLayout_ -> insertWidget(5, sendButton_, 1, Qt::AlignRight);
    
      rButtonLayout_ -> insertWidget(0, receiveButton_, 1);
      rButtonLayout_ -> insertWidget(1, rHomeButton_);
      rButtonLayout_ -> insertWidget(2, rBackButton_);
      rButtonLayout_ -> insertWidget(3, rAddButton_);
      rButtonLayout_ -> insertWidget(4, rRemoveButton_);
      rButtonLayout_ -> insertWidget(5, rRefreshButton_);
    
      buttonLayout_ -> insertLayout(0, lButtonLayout_);
      buttonLayout_ -> insertLayout(1, rButtonLayout_);
    
    on the left layout it is ok, but on the right layout the buttons which should be on the right corner are near the center, can you tell me what is wrong here?
    thank you.
    1 Reply Last reply
    0
    • A Offline
      A Offline
      asanka424
      wrote on 9 Mar 2016, 12:39 last edited by
      #2

      Can you try a spacer to push them to your right

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JohanSolo
        wrote on 9 Mar 2016, 12:47 last edited by
        #3

        In the right layout all the items have the same default alignment, you never specified any specific alignment.

        `They did not know it was impossible, so they did it.'
        -- Mark Twain

        1 Reply Last reply
        1
        • M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 9 Mar 2016, 12:51 last edited by
          #4

          @tokafr said:

          insertWidget

          as @JohanSolo points out, you are not using any aligment which is extra paramter
          http://doc.qt.io/qt-5.5/qboxlayout.html#insertWidget

          1 Reply Last reply
          1
          • T Offline
            T Offline
            tokafr
            wrote on 9 Mar 2016, 16:12 last edited by tokafr 3 Sept 2016, 16:16
            #5

            I do
            insertWidget(1, rHomeButton_, 0, Qt::AlignRight);
            and so on for all buttons
            but it doesn't affect

            1 Reply Last reply
            0

            3/5

            9 Mar 2016, 12:47

            • Login

            • Login or register to search.
            3 out of 5
            • First post
              3/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved