Reputation: 519
I have a
QTableWidget
, QTextEdit
, and cancel & okay buttons.
I want these widgets to stay in the same position relative to each other, and the QTableWidget
to expand if the dialog window is expanded or size changed...
How can I do that?
Upvotes: 3
Views: 13698
Reputation: 7687
You need to look into Qt's layout system - using layouts will handle automatically resizing your objects based on the size of their parent.
A combination of using QWidget::setSizePolicy()
and QBoxLayout::setStretch()
(or more likely QBoxLayout::insertWidget(..., int stretch = 0, ...)
) will allow you to acheive the behaviour you refer to where only certain objects expand to fill available space, while others remain a constant size.
Addressing the image you've given above as an example:
Aside from dragging and dropping objects into the form, to achieve this solution I have:
sizePolicy
of textEdit
to Fixed
.textEdit
's minimumSize
for the sizePolicy
to use.layoutStretch
in centralWidget
to 1,0
, i.e. assign the minimum possible space for the elements contained in horizontalLayout
and give any remaining space to tableWidget
.Upvotes: 13