- C/C++ code
+-----------------------+| || groupBox || |+-----------------------+| || tableView || || |+-----------------------+
如上面的布局,当窗口的大小改变时,gruopBox的高度不变,而tableView的高度随窗口大小改变而改变.
现在我将tableView替换为自定义的Widget,如何实现像tableView那样使高度随窗口大小改变而改变.
听说应该重载resizeEvent(),希望大家给小弟指引一下.
------解决方案--------------------
sizePolicy : QSizePolicy
This property holds the default layout behavior of the widget.
If there is a QLayout that manages this widget's children, the size policy specified by that layout is used. If there is no such QLayout, the result of this function is used.
The default policy is Preferred/Preferred, which means that the widget can be freely resized, but prefers to be the size sizeHint() returns. Button-like widgets set the size policy to specify that they may stretch horizontally, but are fixed vertically. The same applies to lineedit controls (such as QLineEdit, QSpinBox or an editable QComboBox) and other horizontally orientated widgets (such as QProgressBar). QToolButton's are normally square, so they allow growth in both directions. Widgets that support different directions (such as QSlider, QScrollBar or QHeader) specify stretching in the respective direction only. Widgets that can provide scroll bars (usually subclasses of QScrollArea) tend to specify that they can use additional space, and that they can make do with less than sizeHint().