分隔窗口QSplitter類
* 一、新建QT GUI應用,項目名稱爲Splitter,基類選擇QMainWindow,取消"建立界面"
* 二、修改main.cpp字體
#include "mainwindow.h" #include <QApplication> #include<Qsplitter> #include<QTextEdit> #include <QTextCodec> // int main(int argc, char *argv[]) { QApplication a(argc, argv); QFont font("ZYSong18030", 12); a.setFont(font); //指定顯示字體 QSplitter *splitterMain = new QSplitter(Qt::Horizontal, 0); //主分隔窗口,設定此分割窗口爲水平分割窗口 QTextEdit * textLeft = new QTextEdit(QObject::tr("left widget"), splitterMain); //新建一個QTextEdit類,並將其插入主分割窗口中 textLeft->setAlignment(Qt::AlignAbsolute); //設定TextEdit中文字的對齊方式:文字居中 // Qt::AlignCenter,Qt::AlignLeft,Qt::AlignRight, //右部分割窗口 QSplitter *splitterRight =new QSplitter(Qt::Vertical,splitterMain); //垂直分割,並以主分割窗口爲父窗口 splitterRight->setOpaqueResize(false); QTextEdit *textUp =new QTextEdit(QObject::tr("Top Widget"),splitterRight); textUp->setAlignment(Qt::AlignCenter); QTextEdit *textBottom =new QTextEdit(QObject::tr("Bottom Widget"),splitterRight); // textBottom->setAlignment(Qt::AlignCenter); splitterMain->setStretchFactor(1,0); //右邊部分爲可伸縮部件 splitterMain->setWindowTitle(QObject::tr("Splitter")); splitterMain->show(); return a.exec(); }