Reputation: 2658
I have a bunch of standard qt creator dragged-on controls, which I have at the bottom of a window. I have one table widget that I want to expand vertically to be able to display more rows if the window is expanded downwards, less if upwards to a minimum. I want all the other widgets to stick to the bottom of the window as that edge moves. I'm using Qt Creator 2.1.0 and Qt 4.7, and I don't see any flags for the widgets that would do what I need, nor did googling really turn up anything enlightening. Perhaps it has something to do with putting the widgets in a container that moves and/or stretches? Right now, they're just on MainWindow.
Upvotes: 0
Views: 2585
Reputation: 49289
Just set a vertical layout, add a spacer to it, and then your widget. The spacer will push your widget all the way down. Additionally you might want to toy around with the size policies.
Upvotes: 2
Reputation: 1390
It is difficult to know what you are trying to do from your question, but perhaps you are looking for QSplitter.
Alternatively, you can specify various QLayouts for a QWidget, such as QHBoxLayout, QVBoxLayout, QGridLayout, etc. Various widgets can be added to the layout you specify, then you set the layout on a QWidget, so it acts as a container for the widgets you've added to the layout. Stretching and alignment flags can be set as you add your widgets to the layout.
Upvotes: 1
Reputation: 98425
A QMainWindow
should only be used if you need its docking functionality. Otherwise, just use a plain QWidget
. No general purpose child widgets can be "stuck" onto a QMainWindow
. They need to belong to the central widget. All you most likely need to do is to set an Expanding
vertical size policy to the table widget. Designer should do it by default. Here's an example:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTableWidget" name="table">
<row>
<property name="text">
<string>1</string>
</property>
</row>
<column>
<property name="text">
<string>Name</string>
</property>
</column>
<item row="0" column="0">
<property name="text">
<string>fyngyrz</string>
</property>
</item>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="foo">
<property name="text">
<string>Foo</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="bar">
<property name="text">
<string>Bar</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>
Upvotes: 1