QT自适应电脑分辨率,在main函数中最前端设置如下代码
int main(int argc, char *argv[]) { #if (QT_VERSION > QT_VERSION_CHECK(5,6,0)) QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); #endif QApplication a(argc, argv); app app; return a.exec(); }
基本控件布局设置
头文件定义对象
QGridLayout *gridLayout; QGridLayout *tabserialLayout; QHBoxLayout *serialLayout; QGridLayout *tabwifiLayout;
源文件设置布局格式和参数
gridLayout = new QGridLayout; gridLayout->addWidget(ui.tabWidget); gridLayout->setContentsMargins(0,0,0,0); ui.mainwidget->setLayout(gridLayout); /*************************************************************/ tabserialLayout = new QGridLayout; tabserialLayout->addWidget(ui.groupBoxSerial,0,0);//网格布局中的位置设置 tabserialLayout->addWidget(ui.groupBoxCtrl,1,0); tabserialLayout->addWidget(ui.groupBoxMsg,2,0); ui.groupBoxSerial->setFixedHeight(40);//设置布局时候固定高度 tabserialLayout->setRowStretch(1,1);//剩余空间自动伸缩 tabserialLayout->setRowStretch(2,1); tabserialLayout->setContentsMargins(0,0,0,0); ui.tabserial->setLayout(tabserialLayout);//将布局放在哪个控件中 serialLayout = new QHBoxLayout;//水平布局 serialLayout->addWidget(ui.label_serialname); serialLayout->addWidget(ui.comboBox_serialname); ui.label_serialname->setFixedWidth(50); ui.comboBox_serialname->setFixedWidth(200); serialLayout->addWidget(ui.label_bauderate); serialLayout->addWidget(ui.comboBox_bauderate); ui.label_bauderate->setFixedWidth(50); ui.comboBox_bauderate->setFixedWidth(70); serialLayout->addWidget(ui.label_databit); serialLayout->addWidget(ui.comboBox_databit); ui.label_databit->setFixedWidth(50); ui.comboBox_databit->setFixedWidth(70); serialLayout->addWidget(ui.label_stopbit); serialLayout->addWidget(ui.comboBox_stopbit); ui.label_stopbit->setFixedWidth(50); ui.comboBox_stopbit->setFixedWidth(70); serialLayout->addWidget(ui.label_paritybit); serialLayout->addWidget(ui.comboBox_paritybit); ui.label_paritybit->setFixedWidth(50); ui.comboBox_paritybit->setFixedWidth(70); serialLayout->addWidget(ui.OpenSerialPort); ui.OpenSerialPort->setFixedWidth(100); serialLayout->setContentsMargins(10,0,0,0); serialLayout->setAlignment(Qt::AlignLeft); ui.groupBoxSerial->setLayout(serialLayout);
标签:积累,qt,comboBox,代码,label,serialLayout,ui,addWidget,setFixedWidth From: https://www.cnblogs.com/723687715-Q/p/17824702.html