Qt:QSplitter 系统管理员 2023-01-12 11:41 107阅读 0赞 分隔窗口QSplitter类 \* 1、新建QT GUI应用,项目名称为Splitter,基类选择QMainWindow,取消"创建界面" \* 2、修改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(); } ![bf92c466c513e2ea97d85872cb2e4fe5914.jpg][] [bf92c466c513e2ea97d85872cb2e4fe5914.jpg]: /images/20221119/ea9c99c0426e47f083b806f483ca232b.png
还没有评论,来说两句吧...