【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>
结果展示: