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. Add widget to layout with 0 weight/size
Forum Updated to NodeBB v4.3 + New Features

Add widget to layout with 0 weight/size

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

    Is there an easy way to add a widget to a layout with 0 weight?

    My scenario: I want a title QLabel and a small "edit" button to the right of it. I want the title QLabel to be horizontally centered, with the edit button to be to the far right. If I use stretch factors, it still accounts for the edit buttons size, so the QLabel won't be truly centered.

    1 Reply Last reply
    0
    • btseB Offline
      btseB Offline
      btse
      wrote on last edited by
      #2

      I figured out a way to do it using QGridLayout since you can add widgets to the same cell.

      QLabel *title = new QLabel("Title", this);
      QLabel *edit = new QLabel("edit", this);
      
      QGridLayout *titleLayout = new QGridLayout;
      titleLayout->addWidget(title, 0, 0, Qt::AlignCenter);
      titleLayout->addWidget(edit, 0, 0, Qt::AlignRight);
      
      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