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 widgets to the center in QHBoxLayout

Align widgets to the center in QHBoxLayout

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 382 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.
  • D Offline
    D Offline
    DeeDee14
    wrote on last edited by
    #1

    I am creating a new QHBoxLayout and adding two widgets to this layout. I want them to be beside each other and in the center like the image below.

    expected

    Currently, they are aligned horizontally but with a lot of space.

    reality

        auto layout= new QHBoxLayout(this);
        layout->addWidget(button1, 0, Qt::AlignmentFlag::AlignCenter);
        layout->addWidget(button2, 0, Qt::AlignmentFlag::AlignCenter);
    
    M 1 Reply Last reply
    0
    • D DeeDee14

      I am creating a new QHBoxLayout and adding two widgets to this layout. I want them to be beside each other and in the center like the image below.

      expected

      Currently, they are aligned horizontally but with a lot of space.

      reality

          auto layout= new QHBoxLayout(this);
          layout->addWidget(button1, 0, Qt::AlignmentFlag::AlignCenter);
          layout->addWidget(button2, 0, Qt::AlignmentFlag::AlignCenter);
      
      M Offline
      M Offline
      mpergand
      wrote on last edited by mpergand
      #2

      Maybee:
      layout->addWidget(button1, 0, Qt::AlignRight);
      layout->addWidget(button2, 0, Qt::AlignLeft);

      1 Reply Last reply
      0
      • D DeeDee14 has marked this topic as solved on

      • Login

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