寒假学习 第一天
编辑器Qt Creator
一、入门
1.手动布局
QHBoxLayout 平布布局
QVBoxLayout 垂直布局
QLabel 标签
QLineEdit 可以编辑的标签
QPushButton 按钮
#include<QApplication> #include<QLineEdit> #include<QPushButton> #include<QLabel> #include<QWidget> #include<QHBoxLayout> #include<QVBoxLayout> int main(int argc, char **argv) { QApplication app(argc,argv); QLabel *infoLable = new QLabel; QLabel *cmdLabel = new QLabel; QLineEdit *cmdLineEdit = new QLineEdit; QPushButton *submitButton =new QPushButton; QPushButton *cancelButton =new QPushButton; QPushButton *browserButton =new QPushButton; infoLable->setText("Plase input commad"); cmdLabel->setText("Open:"); cmdLineEdit->clear(); submitButton->setText("Submit"); cancelButton->setText("Cancel"); browserButton->setText("brower"); QHBoxLayout *cmdLayout =new QHBoxLayout; cmdLayout->addWidget(cmdLabel); cmdLayout->addWidget(cmdLineEdit); QHBoxLayout *buttonLayout =new QHBoxLayout; buttonLayout->addWidget(submitButton); buttonLayout->addWidget(cancelButton); buttonLayout->addWidget(browserButton); QVBoxLayout *mainLayout =new QVBoxLayout; mainLayout->addWidget(infoLable); mainLayout->addLayout(cmdLayout); mainLayout->addLayout(buttonLayout); QWidget *window =new QWidget; window->setLayout(mainLayout); window->setWindowTitle("Runing.."); window->show(); return app.exec(); return 0; }
手动编译
进入文件的目录运行
localhost first # qmake -project
localhost first # qmake
localhost first # make
就会在目录下生成可执行文件
2.用Qt Creator 布局
打开 界面文件 xxx.cui
就可以看到很多东西,自己托进去。
3.设定窗口大小不可改
到构造函数中 加入
this->setMaximumSize(442,229);
this->setMinimumSize(442,229);
把最大最小的尺寸设置成一样就可以了