【Qt】splitter

一段简单的分割窗口的程序:

<span style="font-size:18px;">#include "mainwindow.h"
#include <QApplication>
#include <QSplitter>
#include <QTextEdit>
#include <QTextCodec>


int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QFont font("ZYSong18030",20);//
    a.setFont(font);//显示指定类型和大小的字体
    //主分割窗口
    QSplitter *splitterMain = new QSplitter(Qt::Horizontal,0);//新建一个Splitter类,作为一个水平分割的分割窗口
    QSplitter *splitterLeft= new QSplitter(Qt::Vertical,splitterMain);
    QTextEdit *textUp = new QTextEdit(QObject::tr("Top Widget"),splitterLeft);
    textUp->setAlignment(Qt::AlignCenter);

    QTextEdit *textBottom = new QTextEdit(QObject::tr("Bottom Widget"),splitterLeft);
    textBottom->setAlignment(Qt::AlignCenter);

    /*QTextEdit *textRight= new QTextEdit(QObject::tr("Right widget"),splitterMain);//创建一个QTextEdit类,插入到主窗口
    textRight->setAlignment(Qt::AlignCenter);//居中设置*/

    //右部分分割窗口
   // QSplitter *splitterLeft= new QSplitter(Qt::Vertical,splitterMain);
    splitterLeft->setOpaqueResize(false);

    QTextEdit *textRight= new QTextEdit(QObject::tr("Right widget"),splitterMain);//创建一个QTextEdit类,插入到主窗口
        textRight->setAlignment(Qt::AlignCenter);

   /* QTextEdit *textUp = new QTextEdit(QObject::tr("Top Widget"),splitterLeft);
    textUp->setAlignment(Qt::AlignCenter);

    QTextEdit *textBottom = new QTextEdit(QObject::tr("Bottom Widget"),splitterLeft);
    textBottom->setAlignment(Qt::AlignCenter);*/

    splitterMain->setStretchFactor(1,1);//第一个参数表示对添加的控键的编号,第二个参数如果大于0,则表示可伸缩
    splitterMain->setWindowTitle(QObject::tr("splitter"));
    splitterMain->show();
    //w.show();

    return a.exec();
}
</span>


 


 

结果展示:

【Qt】splitter_第1张图片

你可能感兴趣的:(qt)