1.文本框与按钮布局
// 创建一个新的QWidget作为QStackedWidget的页面
QWidget *pagewidget = new QWidget();
// 创建一个文本标签
QLabel *label = new QLabel("屏幕设置", pagewidget);
label->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); // 明确设置左对齐
// 创建三个按钮
QPushButton *button1 = new QPushButton("上半屏", pagewidget);
QPushButton *button2 = new QPushButton("下半屏", pagewidget);
QPushButton *button3 = new QPushButton("全屏", pagewidget);
// 设置按钮的固定大小为60x40像素
button1->setFixedSize(60, 40);
button2->setFixedSize(60, 40);
button3->setFixedSize(60, 40);
label->setFixedSize(100, 40);
// 创建一个子布局来放置三个按钮
QHBoxLayout *buttonLayout = new QHBoxLayout();
// 添加按钮到按钮布局中
buttonLayout->addWidget(button1);
buttonLayout->addWidget(button2);
buttonLayout->addWidget(button3);
// 设置按钮之间的间隔(如果需要)
buttonLayout->setSpacing(100); // 例如,5像素的间隔
// 创建一个主布局来管理整个pagewidget
QHBoxLayout *mainLayout = new QHBoxLayout(pagewidget);
// 将文本标签添加到主布局中
mainLayout->addWidget(label);
// 在标签和按钮布局之间添加一个固定的间隔
mainLayout->addSpacing(300); // 例如,20像素的间隔
// 将按钮布局作为一个整体添加到主布局中
mainLayout->addLayout(buttonLayout);
// 设置边距(如果需要)
mainLayout->setContentsMargins(10, 10, 10, 10);
// 设置文本框(或QLineEdit)字体颜色为橙色
label->setStyleSheet("QLabel { border: 1px solid black; padding: 2px; color: orange; }");
// 设置按钮字体颜色为白色
button1->setStyleSheet("QPushButton { color: white; }");
button2->setStyleSheet("QPushButton { color: white; }");
button3->setStyleSheet("QPushButton { color: white; }");
// 将布局设置给QWidget
pagewidget->setLayout(mainLayout);
// 将QWidget添加到QStackedWidget中,并获取其索引
int index = ui->stackedWidget->addWidget(pagewidget);
qDebug()<<"index-->"<<index;
// 设置QStackedWidget的当前页面为新添加的页面
ui->stackedWidget->setCurrentIndex(index);
// 使用QOverload和lambda表达式连接按钮的clicked信号
connect(button1, &QPushButton::clicked, this, [=]() {
wavesetpopupPage=0;
qDebug() << "按钮1被点击,标志位:" << wavesetpopupPage;
});
connect(button2, &QPushButton::clicked, this, [=]() {
wavesetpopupPage=1;
qDebug() << "按钮1被点击,标志位:" << wavesetpopupPage;
});
connect(button3, &QPushButton::clicked, this, [=]() {
wavesetpopupPage=2;
qDebug() << "按钮1被点击,标志位:" << wavesetpopupPage;
});