使用Qplitter实现页面的三布局分布
1.新建一个无ui界面的工程,其基类为mainwindow
2.代码实现
mainwindow.h和main.cpp无改动。默认
mainwindow.cpp
#include
"mainwindow.h"
#include
<QSplitter>
#include
<QTextEdit>
MainWindow
::MainWindow(QWidget
*parent
)
: QMainWindow(parent
)
{
QSplitter
* mainsplitter
= new QSplitter(Qt
::Horizontal
);
QTextEdit
* leftedit
= new QTextEdit(QObject
::tr("左窗口"),mainsplitter
);
leftedit
->setAlignment(Qt
::AlignCenter
);
QSplitter
* rightedit
= new QSplitter(Qt
::Vertical
,mainsplitter
);
QTextEdit
* upedit
= new QTextEdit(QObject
::tr("上窗口"),rightedit
);
upedit
->setAlignment(Qt
::AlignCenter
);
QTextEdit
* downedit
= new QTextEdit(QObject
::tr("下窗口"),rightedit
);
downedit
->setAlignment(Qt
::AlignCenter
);
mainsplitter
->setWindowTitle(QObject
::tr("分割窗口"));
setCentralWidget(mainsplitter
);
mainsplitter
->show();
}
MainWindow
::~MainWindow()
{
}
3.效果展示
用代码实现的分裂器较之ui界面的更灵活。可随处拖拽
转载请注明原文地址: https://win8.8miu.com/read-4080.html