首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > QT开发 >

自定义Widget,该怎么解决

2012-05-05 
自定义WidgetC/C++ code+-----------------------+|||groupBox|||+-----------------------+|||tableView|

自定义Widget

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().

热点排行