qt 教程 之 窗体布局

#include<QApplication> #include<QLabel> #include<QTextCodec> #include<QPushButton> #include<QVBoxLayout> #include<QHBoxLayout> #include<QCheckBox> #include<QLineEdit> int main(int argc, char *argv[]) { QApplication app(argc,argv); QTextCodec::setCodecForTr(QTextCodec::codecForName("utf-8")); QWidget* widget=new QWidget;//主窗体 QHBoxLayout* topLayout=new QHBoxLayout;//窗体左边部分的上面两个部件 QLabel *label=new QLabel(QObject::tr("姓名")); QLineEdit*lineEdit=new QLineEdit; topLayout->addWidget(label); topLayout->addWidget(lineEdit); QCheckBox*check1=new QCheckBox(QObject::tr("忽略大小写")); QCheckBox*check2=new QCheckBox(QObject::tr("向前查找")); QVBoxLayout*leftLayout=new QVBoxLayout;//窗体左边部分 leftLayout->addLayout(topLayout); leftLayout->addWidget(check1); leftLayout->addWidget(check2); QPushButton *bt1=new QPushButton(QObject::tr("确定")); QPushButton*bt2=new QPushButton(QObject::tr("取消")); QVBoxLayout*rightLayout=new QVBoxLayout;//窗体的有半部分 rightLayout->addWidget(bt1); rightLayout->addWidget(bt2); QHBoxLayout *mainLayout=new QHBoxLayout;//总体布局 mainLayout->addLayout(leftLayout); mainLayout->addLayout(rightLayout); widget->setLayout(mainLayout); widget->show(); return app.exec(); }

你可能感兴趣的:(qt,BT)