Qt 常用小部件编程指南
1. 布局窗口代码与布局原理
在布局窗口的代码中,使用了水平和垂直两种盒式布局小部件来排列其他小部件。垂直布局包含两个标签,分别标记为“Top”和“Bottom”;水平布局则包含一个显示为“Right”的标签以及垂直布局。可以像示例中那样,在布局小部件内部自由放置其他布局小部件。
以下是使用布局的代码示例:
// 假设在 LayoutWindow.cpp 中
// 创建垂直布局
QVBoxLayout *verticalLayout = new QVBoxLayout();
QLabel *topLabel = new QLabel("Top");
QLabel *bottomLabel = new QLabel("Bottom");
verticalLayout->addWidget(topLabel);
verticalLayout->addWidget(bottomLabel);
// 创建水平布局
QHBoxLayout *horizontalLayout = new QHBoxLayout();
QLabel *rightLabel = new QLabel("Right");
horizontalLayout->addWidget(rightLabel);
horizontalLayout->addLayout(verticalLayout);
2. QLineEdit 小部件
QLineEdit 是 Qt 的单行文本输入小部件,适用于输入简短文本,如用户的名字。可以使用输入掩码限制文本输入以符合特定模板,还能应
超级会员免费看
订阅专栏 解锁全文
966

被折叠的 条评论
为什么被折叠?



