1.horizontal line 和vertical line 的使用
horizontal line 和vertical line 实际上是由QFame类,设置相应的参数来实现的;而不是由单独的类来实现的,例如(QHorizontalLine/QVerticalLine);
1.1.控件拖拽
1.2.代码实现
1 QFrame *line = new QFrame();
2 line->setFrameShape(QFrame::HLine);
3 line->setFrameShadow(QFrame::Plain);
4 //line->raise();//顶层展示
2.horizontal line 和vertical line 在QGridLayout 中的应用
以下为代码实现:
1 #include "mainwindow.h"
2 #include "ui_mainwindow.h"
3 #include "testform.h"
4 #include <QDebug>
5 #include <QGridLayout>
6 #include <QHBoxLayout>
7 #include <QPushButton>
8 #include <QLabel>
9
10
11 MainWindow::MainWindow(QWidget *parent) :
12 QMainWindow(parent),
13 ui(new Ui::MainWindow)
14 {
15 ui->setupUi(this);
16
17 QGridLayout *m_Layout = new QGridLayout(this);
18 m_Layout->setSpacing(5);//setVerticalSpacing()/setHorizontalSpacing()
19
20 //1.创建标题1
21 QLabel *m_title = new QLabel(tr("题目1"));
22 m_title->setMinimumHeight(50);
23 m_title->setMaximumHeight(60);
24 m_title->setAlignment(Qt::AlignCenter);
25 m_Layout->addWidget(m_title, 0, 0, 1, 1);
26
27 //分割线
28 QFrame *line = new QFrame();
29 line->setFrameShape(QFrame::HLine);
30 line->setFrameShadow(QFrame::Plain);
31 //line->raise();//顶层展示
32 m_Layout->addWidget(line,1,0,1,1);
33
34 //2.创建标题2
35 m_title = new QLabel(tr("题目2"));
36 m_title->setAlignment(Qt::AlignCenter);//Qt::AlignHCenter|Qt::AlignTop
37 m_Layout->addWidget(m_title, 2, 0, 1, 1);
38
39 resize(400, 4*30);
40 ui->centralWidget->setLayout(m_Layout);
41 }
42
43 MainWindow::~MainWindow()
44 {
45 delete ui;
46 }
呈现效果: