Questions tagged [qlayout]

The QLayout class, part of the Qt framework, is the base class of geometry managers.

This is an abstract base class inherited by the concrete classes QBoxLayout, QGridLayout, QFormLayout, and QStackedLayout.

Documentation can be found here for Qt 4.8 and here for Qt 5.

239 questions
62
votes
6 answers

QVBoxLayout: How to vertically align widgets to the top instead of the center

In Qt, When I add widgets to my layout, they are vertically centered by default. Is there a way to "List" the widgets from top to bottom instead of centering them vertically?
sFuller
  • 1,305
  • 2
  • 14
  • 23
32
votes
1 answer

QLayout: Attempting to add QLayout "" to QWidget "", which already has a layout

I want to create some tabs, and I read this answer: How to add a tab in PySide I use the code in the answer and made some changes. Cause my code has to read some files and get the name of my tabs from those file, so that I add a for loop in my code.…
EricBkc
  • 369
  • 2
  • 4
  • 12
27
votes
2 answers

PySide: Removing a widget from a layout

I'm trying to remove a Qt widget from a layout in a PySide application. Here is a minimal example. It is a widget with 5 buttons in it, and the middle one is supposed to remove itself when clicked: import sys from PySide import QtGui app =…
Etienne Perot
  • 4,764
  • 7
  • 40
  • 50
19
votes
2 answers

Setting text on a QLabel in a layout, doesn't resize

Using the designer in Qt creator I have created a dialog that contains various widgets in a vertical layout. One of the widgets is a QLabel with word wrap set to true. The text for the QLabel is set just before the dialog is shown. The maximum width…
TheDarkKnight
  • 27,181
  • 6
  • 55
  • 85
16
votes
2 answers

Resize window to fit content

I have a QGLWidget, which I want to resize to a given resolution (bigger than the containing window). My intention is, that the window expands until the widget fits inside, but can't find a way to do it. I tried several commands after resizing the…
12
votes
1 answer

Set background color of layout

As the layout object has no attribute ".setStyleSheet()", how can one set the background color for a given layout? As a visual explanation, I can set both the label and the button background color, but not the entire layout, which includes the…
user-2147482637
  • 2,115
  • 8
  • 35
  • 56
8
votes
1 answer

QGridLayout different column width

I am trying to create a layout looking like this: _________ | | | |1 | 2 | |__|______| | 3 | 4 | |____|____| Basically, I want cell number 1 the first row to be thinner that cell 2, but cells number 3 and 4 on the second row should have…
hoan
  • 1,277
  • 3
  • 18
  • 32
8
votes
2 answers

Resizable layouts/frames in Qt, per widget by the user

I use QGridLayout very often, and there's a requirement I don't know how to or if I can achieve with this kind of layouts. My question: Imagine I have two normal widgets (derived from QWidget) on the left and right (on something like QHBoxLayout or…
The Quantum Physicist
  • 24,987
  • 19
  • 103
  • 189
8
votes
2 answers

Set content margins from stylesheet

I'm struggling to set content margins to zero from QLayout objects in Qt with a stylesheet. I can remove them with QLayout::setContentsMargins(0, 0, 0, 0) but I would prefer to do it from stylesheet.
Ben
  • 966
  • 2
  • 10
  • 24
7
votes
1 answer

Align every widget of a QHBoxLayout to the top

I'm trying to align every widgets in a QHBoxlayout to the top but what I get is every widget seems centered. I think this is due to there different sizes. For instance with: from PyQt5.QtGui import * from PyQt5.QtCore import * from PyQt5.QtWidgets…
ymmx
  • 4,769
  • 5
  • 32
  • 64
6
votes
3 answers

QGridLayout, 3 panes, not expanding properly

I'm trying to layout a window (all in code) with a QGridLayout. I can add widgets to the layout and they display in my window, but I can't figure out how to resize them properly. Here's what I'd…
jbrennan
  • 11,943
  • 14
  • 73
  • 115
6
votes
1 answer

Applying a layout to a QDockWidget in PyQt5

I'm trying to create a docked interface in PyQt5, creating a BoxLayout contining my various widgets, and then applying this layout to the QDockWidget. My approach so far has been: self.layout =…
Masutatsu
  • 434
  • 1
  • 7
  • 19
6
votes
1 answer

How to properly size Qt widgets?

Main Question What is the "right" way to give your widgets default sizes and make sure they contract, expand, or remain fixed if there is additional or not enough space to accommodate them? How I Think Qt Works After reading the Qt documentation it…
Ed LaFave
  • 399
  • 3
  • 11
6
votes
3 answers

Align to the right text from QLabel and QLineEdit

I have a QLabel just below a QLineEdit with the same size and alignment properties: QLineEdit *lineEdit = new QLineEdit("999"); lineEdit->setFixedWidth(100); lineEdit->setAlignment(Qt::AlignRight); // QLabel *label = new…
mimo
  • 2,469
  • 2
  • 28
  • 49
6
votes
1 answer

How to find widgets of a given type in a QLayout?

I am able to find the QRadioButton this way: for(int i = 0; i < ui->verticalLayout->count(); i++) { QRadioButton* r = qobject_cast(ui->verticalLayout->itemAt(i)->widget()); if(r->isChecked()) //found it! } But I don't…
dsalaj
  • 2,857
  • 4
  • 34
  • 43
1
2 3
15 16