1 // 3.1 分割窗口 QSplitter类
2 #include "mainwindow.h"
3 #include <QApplication>
4 #include <QSplitter>
5 #include <QTextEdit>
6 int main(int argc, char *argv[])
7 {
8 QApplication a(argc, argv);
9 QFont font("ZYSong18030",12);
10 a.setFont(font);
11 QSplitter *splitterMain = new QSplitter(Qt::Horizontal,0);
12 QTextEdit *textLeft = new QTextEdit(QObject::tr("Left Widgte"),splitterMain);
13 textLeft->setAlignment(Qt::AlignCenter);
14 QSplitter *splitterRight =new QSplitter(Qt::Vertical,splitterMain);
15 QTextEdit *textUp = new QTextEdit(QObject::tr("Top Widget"),splitterRight);
16 textUp->setAlignment(Qt::AlignCenter);
17 QTextEdit *textBottom = new QTextEdit(QObject::tr("Bottom Widget"),splitterRight);
18 textBottom->setAlignment(Qt::AlignCenter);
19 splitterMain->setStretchFactor(1,1);//第一个参数:索引;第二个参数:大于零则可伸缩
20 splitterRight->setOpaqueResize(false);//是否在拖拽时实时更新显示
21 splitterMain->setWindowTitle(QObject::tr("Splitter"));
22 splitterMain->show();
23 //MainWindow w;
24 //w.show();
25 return a.exec();
26 }