qt界面布局练习
扫描二维码
随时随地手机看文章
1. [代码][C/C++]代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#include <QApplication> #include "qtestdialog.h" TestDialog::TestDialog(QWidget *parent) : QDialog(parent) { pushButton_1 = new QPushButton(tr( "字体" )); pushButton_2 = new QPushButton(tr( "大小" )); pushButton_3 = new QPushButton(tr( "消息记录" )); QHBoxLayout* toolLayout = new QHBoxLayout; toolLayout->addWidget(pushButton_1); toolLayout->addWidget(pushButton_2); toolLayout->addStretch(); toolLayout->addWidget(pushButton_3); pushButton_4 = new QPushButton(tr( "关闭" )); pushButton_5 = new QPushButton(tr( "发送" )); QHBoxLayout* buttomLayout = new QHBoxLayout; buttomLayout->addStretch(); buttomLayout->addWidget(pushButton_4); buttomLayout->addWidget(pushButton_5); textEdit_1 = new QTextEdit; textEdit_2 = new QTextEdit; textEdit_2->setMaximumHeight(90); QVBoxLayout* leftlayout = new QVBoxLayout; leftlayout->addWidget(textEdit_1); leftlayout->addLayout(toolLayout); leftlayout->addWidget(textEdit_2); leftlayout->addLayout(buttomLayout); textEdit_3 = new QTextEdit; textEdit_3->setMaximumWidth(100); QVBoxLayout* rightlayout = new QVBoxLayout; rightlayout->addWidget(textEdit_3); QHBoxLayout* toplayout = new QHBoxLayout; toplayout->addLayout(leftlayout); toplayout->addLayout(rightlayout); QHBoxLayout *mainLayout = new QHBoxLayout; mainLayout->addLayout(toplayout); setLayout(mainLayout); } |
2. [代码][C/C++]代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#ifndef QTESTDIALOG_H #define QTESTDIALOG_H #include <QDialog> #include <QTextEdit> #include <QPushButton> #include <QLayout> class TestDialog: public QDialog { Q_OBJECT public : TestDialog(QWidget *parent = 0); private : QTextEdit* textEdit_1; QTextEdit* textEdit_2; QTextEdit* textEdit_3; QPushButton* pushButton_1; QPushButton* pushButton_2; QPushButton* pushButton_3; QPushButton* pushButton_4; QPushButton* pushButton_5; }; |
3. [代码][C/C++]代码
1
2
3
4
5
6
7
8
9
10
|
#include <QApplication> #include "QTestDialog.h" int main( int argc, char *argv[]) { QApplication a(argc, argv); TestDialog* tdialog = new TestDialog; tdialog->show(); return a.exec(); } |