在QT中,如何在自定义小部件中定义布局的几何形状
In QT, How to define the geometry for the Layout in a custom Widget
在自定义QWidget
(例如MyWidget
)中,我包含了一个管理子部件的布局:
MyWidget window;
QPushButton button;
QVBoxLayout layout(window);
layout.addWidget(button);
window.show();
我希望布局是在一个特定的位置和大小,默认情况下,QWidget将其设置为整个几何。
我如何设置layout
将考虑管理他的空间的几何?
作为间接疑问句:布局使用哪个函数来设置子几何?
QPushButton *button = new QPushButton;
verticalLayout->addSpacing(300);
verticalLayout->addWidget(button);
button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
button->setMinimumSize(500, 200);
button->setMaximumSize(500, 200);
如果您需要垂直和水平间距-使用QGridLayout
QLayout使用两者的摘要作为页边距:
- 父部件内容页边距
- 布局内容页边距
this->setContentsMargins(left, top, right, bottom);
// ...
layout->setContentsMargins(0,0,0,0);
Layout setGeometry由QWidget resize事件调用,并根据它设置子部件的大小。由于并非所有函数都是虚函数,因此不可能(或至少很难)修改这种行为。
相关文章:
- 在提升multi_index容器中,是否定义了"default index"?
- #定义c-预处理器常量..我做错了什么
- 用C++中的一个变量定义一个常量
- Qt自定义QPush按钮未显示在布局上
- C++对象布局是否必须静态定义?
- COM 互操作结构定义与内存布局不匹配
- Qt:自定义小部件的多个布局
- QT设计器中的自定义小部件在框架中具有预先存在的布局
- 重叠小部件的 QT 自定义布局示例无法编译
- 动态地将自定义 qt 小部件添加到框架中,而无需每次都更改布局
- Boost.Proto:具有自定义终端类的EDSL的常规类布局
- 将自定义小部件动态添加到烘焙布局中
- 如何为log4cplus创建自定义布局
- DirectX 11:如何在使用多个顶点缓冲区时定义输入布局
- c++ 14中标准布局类的定义
- 如何布局自定义二进制文件格式
- 在布局中显示自定义小部件
- 在QT中,如何在自定义小部件中定义布局的几何形状
- 自定义布局在Qt设计器
- 向布局中添加小部件仅在自定义类的构造函数中有效