qt 分割窗口
程序员文章站
2024-03-15 15:41:23
...
左右分隔窗口例子:
#include "mainwindow.h"
#include <QApplication>
#include <QSplitter>
#include <QTextEdit>
#include <QTextCodec>
#include <QDebug>
#pragma execution_character_set("utf-8")
int main(int argc, char *argv[])
{
qDebug("Mainframe start...\n");
QApplication a(argc, argv);
QFont font("ZYSong18030" ,12);
a.setFont(font);
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
//主窗口左右分隔
QSplitter *splitMain=new QSplitter(Qt::Horizontal,0);
//QTextEdit *textLeft=new QTextEdit(QObject::tr("left Widget"),splitMain);
QTextEdit *textLeft=new QTextEdit();
textLeft->setAlignment(Qt::AlignCenter);
textLeft->setText(QObject::tr("左窗口 "));
QTextEdit *pRightEdt =new QTextEdit();
pRightEdt ->setAlignment(Qt::AlignCenter);
pRightEdt ->setText(QObject::tr("右窗口 "));
splitMain->addWidget(textLeft);
splitMain->addWidget(pRightEdt);
splitMain->setStretchFactor(0, 1);//下面两句设置左右两列的宽度比为1:4
splitMain->setStretchFactor(1, 4);
splitMain->setWindowTitle(QObject::tr("Splitter 窗口例子"));
splitMain->show();
//MainWindow w;
//w.show();
return a.exec();
}
运行效果如下:
左右(上下)拆分
#include "mainwindow.h"
#include <QApplication>
#include <QSplitter>
#include <QTextEdit>
#include <QTextCodec>
#include <QDebug>
#pragma execution_character_set("utf-8")
int main(int argc, char *argv[])
{
qDebug("Mainframe start...\n");
QApplication a(argc, argv);
QFont font("ZYSong18030" ,12);
a.setFont(font);
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
//主窗口左右分隔
QSplitter *splitMain=new QSplitter(Qt::Horizontal,0);
QTextEdit *textLeft=new QTextEdit(QObject::tr("left Widget"),splitMain);
textLeft->setAlignment(Qt::AlignCenter);
splitMain->addWidget(textLeft);
splitMain->setStretchFactor(0, 1);//下面两句设置左右两列的宽度比为1:4
splitMain->setStretchFactor(1, 4);
QSplitter *pRightSpliter = new QSplitter(Qt::Vertical, splitMain);
QTextEdit* pRightTopEdt = new QTextEdit(pRightSpliter);
pRightTopEdt->setText(QObject::tr("右上窗口"));
QTextEdit* pRightBtmEdt = new QTextEdit(pRightSpliter);
pRightBtmEdt->setText(QObject::tr("右下窗口"));
pRightSpliter->setStretchFactor(0, 1);//右面窗口上下窗口高度比为1:4
pRightSpliter->setStretchFactor(1, 4);
splitMain->setWindowTitle(QObject::tr("Splitter 窗口例子"));
splitMain->show();
//MainWindow w;
//w.show();
return a.exec();
}
界面如下:
推荐阅读
-
qt 分割窗口
-
【Java字符串分割[split()]和截取[substring()]】
-
Spark1.4.0-SparkSQL与Hive整合-支持窗口分析函数 博客分类: hiveSpark sparkSQL与Hive整合
-
语义分割之《Dual Attention Network for Scene Segmentation》论文阅读
-
语义分割 调色板代码
-
Keras框架使用Vnet2d模型对遥感图像语义分割
-
语义分割之《Fully Convolutional Networks for Semantic Segmentation》论文阅读
-
C++ 实现 语义分割 deeplab_v3
-
如何将nDSM等高程数据用于语义分割
-
keras框架下dense_unet对稻田草地分割