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. QLineEdit doesn't stretch to occupy full space in the layout

QLineEdit doesn't stretch to occupy full space in the layout

Scheduled Pinned Locked Moved General and Desktop
qgridlayoutqlineeditstretchmacsizepolicyqtformac
2 Posts 2 Posters 4.0k 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.
  • B Offline
    B Offline
    bharath144
    wrote on last edited by
    #1

    Hello,

    I have a an application which uses a QLineEdit in a QGridLayout to display/edit some text. The following piece of is what I use to construct and add the widget into the layout.

    // ...
    QLineEdit *edit = new QLineEdit;
    edit->setReadOnly(true);
    edit->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum);
    edit->setAlignment(Qt::AlignCenter);
    
    // ...
    
    QGridLayout *layout = new QGridLayout;
    layout->addWidget(promptLabel, 0, 0, 1, 1, Qt::AlignLeft);
    layout->addWidget(new QLabel(""), 0, 1, 1, 1);
    layout->addWidget(edit, 0, 2, 1, 2, Qt::AlignLeft);
    layout->addWidget(new QLabel(""), 0, 4, 1, 1);
    layout->addWidget(selector, 0, 5, 1, 1, Qt::AlignLeft); 
    
    // ...
    

    This is how the output looks. http://imgur.com/AHgIVi2

    I have set the horizontal stretch factor to 1 using the setHorizontalStretch function, but it didn't help. Note that this layout is part of another large layout with a few more widgets and my main widget's layout is governed via layouts (i.e., no fixed size provided).

    Any help would be much appreciated.

    Cheers!
    ಮೈ ಗೋ ಭರತ ನಾರಾಯಣ
    Bharath Narayan M G

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SunyataZero
      wrote on last edited by
      #2

      Hi, this is old now but in case someone else finds this:
      I managed to solve this problem by using
      setSizeConstraint(QtWidgets.QLayout.SetNoConstraint)
      for a layout holding the QLineEdit widget. Actually it wasn't the layout holding the widget, but the layout holding that layout, so you may need to experiment to find out where you need to make this update (or just use SetNoConstraint for all your layouts)
      I hope this helps someone!

      1 Reply Last reply
      1

      • Login

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