Qt Widgets——子区域和子窗口
QMdiArea 一般使用于主窗口QMainWindow,用于容纳多个子窗口QMdiSubWindow
qt creator 3.0的设计师有MdiArea可直接拖入使用。
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QSize>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->actionNew,SIGNAL(triggered()),this,SLOT(creatNewWin()));//actionNew是通过设计师创建的动作 } void MainWindow::creatNewWin()
{
mdiWin1=new QMdiSubWindow;
mdiWin1->setWindowTitle("未定");
ui->mdiArea->addSubWindow(mdiWin1);
mdiWin1->resize(QSize(,));
mdiWin1->show();
}
MainWindow::~MainWindow()
{
delete ui;
}
______________________________________________________________________________________________
QMdiArea
QMdiArea(QWidget * parent = )
~QMdiArea() QMdiSubWindow * addSubWindow(QWidget * widget, Qt::WindowFlags windowFlags = )
void removeSubWindow(QWidget * widget)
void setActivationOrder(WindowOrder order)//设置激活顺序,默认以创建先后激活,槽函数中有调用,枚举值见1
void setBackground(const QBrush & background)//设置背景,默认灰色
void setDocumentMode(bool enabled)
void setOption(AreaOption option, bool on = true)//现只有一个选项,即创建子窗口,窗口不充满这个区域,默认是充满的,枚举值见2
void setViewMode(ViewMode mode)//设置视口模式,默认area中很多小窗口,也可以是有tabBar形式的,以下这些设置tab的函数,都需要先开启这个。枚举值见3
void setTabPosition(QTabWidget::TabPosition position)//设置tabBar的方位,有东西南北四方位,遵循地理的上北下南左西右东枚举值见4
void setTabShape(QTabWidget::TabShape shape)//设置tab的形状,默认长方形,也可以像谷歌浏览器那样,梯形,枚举值见5
void setTabsClosable(bool closable)//默认否,设为true时,tab上方形成一个关闭小按钮
void setTabsMovable(bool movable)//设置是否可移动,默认false,可移动时,可拖动tab在tabBar上移动,现在的浏览器大多有这样的功能 QList<QMdiSubWindow *> subWindowList(WindowOrder order = CreationOrder) const
QMdiSubWindow * currentSubWindow() const
WindowOrder activationOrder() const
QBrush background() const
bool documentMode() const
bool testOption(AreaOption option) const
QMdiSubWindow * activeSubWindow() const
QTabWidget::TabPosition tabPosition() const
QTabWidget::TabShape tabShape() const
bool tabsClosable() const
bool tabsMovable() const
ViewMode viewMode() const
Public Slots
void activateNextSubWindow()
void activatePreviousSubWindow()
void cascadeSubWindows()
void closeActiveSubWindow()
void closeAllSubWindows()
void setActiveSubWindow(QMdiSubWindow * window)
void tileSubWindows()//将所有子窗口在area的可视部分排列整齐
Signals
void subWindowActivated(QMdiSubWindow * window)//切换激活的窗口时发出
1,enum QMdiArea::WindowOrder
| Constant | Value | Description |
|---|---|---|
| QMdiArea::CreationOrder | 0 | 按创建时的先后顺序 |
| QMdiArea::StackingOrder | 1 | 堆叠顺序 |
| QMdiArea::ActivationHistoryOrder | 2 | 按激活历史前后顺序. |
2,enum QMdiArea::AreaOption
flags QMdiArea::AreaOptions
| Constant | Value | Description |
|---|---|---|
| QMdiArea::DontMaximizeSubWindowOnActivation | 0x1 | 激活时不使它最大化,默认是最大化的 |
3,QMdiArea::ViewMode
| Constant | Value | Description |
|---|---|---|
| QMdiArea::SubWindowView | 0 | 以小窗口形式显示(default). |
| QMdiArea::TabbedView | 1 | 不仅可小窗口,而且形成tabBar |
4,enum QTabWidget::TabPosition
| Constant | Value | Description |
|---|---|---|
| QTabWidget::North | 0 | 上方显示 |
| QTabWidget::South | 1 | 下 |
| QTabWidget::West | 2 | 左 |
| QTabWidget::East | 3 | 右 |
5,enum QTabWidget::TabShape
| Constant | Value | Description |
|---|---|---|
| QTabWidget::Rounded | 0 | 字面是圆形,但win7上更像长方形,default |
| QTabWidget::Triangular | 1 | 字面三角形,说它是梯形更好些 |
在以上代码中修改,图中是执行tileSubWindows()函数后的结果:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QSize>
#include <QTabWidget>
#include <QBrush>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QBrush b=QBrush(QColor(,,),Qt::FDiagPattern);
ui->mdiArea->setBackground(b);
ui->mdiArea->setViewMode(QMdiArea::TabbedView);
ui->mdiArea->setTabPosition(QTabWidget::North);
ui->mdiArea->setTabsClosable(true);
ui->mdiArea->setTabsMovable(true);
ui->mdiArea->setTabShape(QTabWidget::Triangular);
ui->mdiArea->setOption(QMdiArea::DontMaximizeSubWindowOnActivation); connect(ui->actionNew,SIGNAL(triggered()),this,SLOT(creatNewWin())); } void MainWindow::creatNewWin()
{
mdiWin1=new QMdiSubWindow;
mdiWin1->setWindowTitle("未定");
ui->mdiArea->addSubWindow(mdiWin1);
mdiWin1->resize(QSize(,));
mdiWin1->show();
}
MainWindow::~MainWindow()
{
delete ui;
} void MainWindow::on_pushButton_clicked()
{
ui->mdiArea->tileSubWindows();
}
______________________________________________________________________________________________
QMdiSubWindow(QWidget * parent = , Qt::WindowFlags flags = )
~QMdiSubWindow() void setKeyboardPageStep(int step)
void setKeyboardSingleStep(int step)
void setOption(SubWindowOption option, bool on = true)//未试效果,求补充,枚举值见1
void setSystemMenu(QMenu * systemMenu).se.
void setWidget(QWidget * widget)//主要通过个函数添加它的小部件 int keyboardPageStep() const
int keyboardSingleStep() const
QMdiArea * mdiArea() const
QMenu * systemMenu() const
QWidget * widget() const
bool testOption(SubWindowOption option) const
bool isShaded() const
Public Slots
| void | showShaded() |
| void | showSystemMenu() |
| void | aboutToActivate() |
| void | windowStateChanged(Qt::WindowStates oldState, Qt::WindowStates newState) |
1,enum QMdiSubWindow::SubWindowOption
| Constant | Value | Description |
|---|---|---|
| QMdiSubWindow::RubberBandResize | 0x4 | If you enable this option, a rubber band control is used to represent the subwindow's outline, and the user resizes this instead of the subwindow itself. As a result, the subwindow maintains its original position and size until the resize operation has been completed, at which time it will receive a single QResizeEvent. By default, this option is disabled. |
| QMdiSubWindow::RubberBandMove | 0x8 | If you enable this option, a rubber band control is used to represent the subwindow's outline, and the user moves this instead of the subwindow itself. As a result, the subwindow remains in its original position until the move operation has completed, at which time aQMoveEvent is sent to the window. By default, this option is disabled. |
Qt Widgets——子区域和子窗口的更多相关文章
- Qt Widgets——主窗口及其主要组成部分
Main Window and Related Classes QAction 动作类,用于当做一个菜单项或工具项插入菜单或工具栏 QActionGroup 动作组,用于管理多个动作,设置它们之间的互 ...
- 使用Python实现子区域数据分类统计
目录 前言 geopandas简介 子区域数据分类统计 总结 一.前言 最近碰到一个需求,需要统计某省内的所有市的某数据分布情况信息.现有该省的数据分布情况以及该省的行政区划数据.我通过 ...
- QT中关闭应用程序和窗口的函数(quit(),exit()以及close()的区别)
使用QT编辑界面,其中带来很大方便的一点就是Qt中自带丰富的.种类齐全的类及其功能函数,程序员可以在编辑程序的过程中简单地直接调用.关于窗口关闭的操作,在这里指出常用的三个槽,即quit(),exit ...
- c# 子线程打开子窗体
下边是在子线程打开子窗口,结果跑到else 里边了跨线程操作窗体控件InvokeRequired失效,无法用于打开子窗体,addonetwo.InvokeRequired,访问不了呢? 大神知道帮忙回 ...
- 公布Qt Widgets桌面应用程序的方法
公布Qt Widgets桌面应用程序的方法 Qt是一款优秀的跨平台开发框架,它能够在桌面.移动平台以及嵌入式平台上执行.眼下Qt 5介绍程序公布的文章帖子比較少.大家又很想要知道怎样公布Qt应用程序, ...
- CSS 实现:父元素包含子元素,子元素垂直居中布局
☊[实现要求]:父元素包含子元素,子元素垂直居中布局 <div class="demo5"> <div class="child">A& ...
- QT5中的pro文件中为何要加入"QT += widgets"
在pro文件里写"QT+=widgets"表示引入QtWidget这个module,qmake在生成makefile的时候,会设置好include path 和 lib path, ...
- 【QT相关】Qt Widgets Module
Qt Widgets Module:提供了一些列UI元素. 使用: //头文件包含 #include <QtWidgets> //链接模式,在.pro文件中添加行: QT += widge ...
- Sql Server的艺术(六) SQL 子查询,创建使用返回多行的子查询,子查询创建视图
子查询或内部查询或嵌套查询在另一个SQL查询的查询和嵌入式WHERE子句中. 子查询用于返回将被用于在主查询作为条件的数据,以进一步限制要检索的数据. 子查询可以在SELECT,INSERT,UPDA ...
随机推荐
- Java中String型与Date型数据的互相转换
/** * Date类型转为指定格式的String类型 * * @param source * @param pattern * @return */ public static String Dat ...
- WAI-ARIA无障碍网页应用属性完全展示
本文为原创辛苦之作,尊重劳动,转载请注明来自张鑫旭-鑫空间-鑫生活[http://www.zhangxinxu.com]本文地址:http://www.zhangxinxu.com/wordpress ...
- Redis 个人理解总结
一.什么是Redis ? Redis(remote dictionnary server)是一个key-value存储系统.Redis是一个开源的使用ANSI C语言编写.遵守BSD协议.支持网络.可 ...
- 一: vue的基本使用
一: vue的下载 vue.js是目前前端web开发最流行的工具库之一,由尤雨溪在2014年2月发布的. 另外几个常见的工具库:react.js /angular.js 官方网站: 中文:http ...
- SpringBoot整合Graylog3.0
Graylog简介 Graylog是一个开源的完整的日志管理工具,功能和ELK类似,安装部署更方便. 官方网站 https://www.graylog.org 搭建 使用docker快速搭建 参考 h ...
- link和@import区别
推荐使用:link 区别 1.从属关系区别@import是 CSS 提供的语法规则,只有导入样式表的作用:link是HTML提供的标签,不仅可以加载 CSS 文件,还可以定义 RSS.rel 连接属性 ...
- 最新省市区数据,sql插入语句
--省数据 insert into Province (ProvinceName) values('北京市'); insert into Province (ProvinceName) value ...
- PHP中json数组与对象的问题
在PHP后端,对于数组和对象的区分不是很大,主要用到的数组居多,而PHP提供接口时响应的一般是json数据(为什么使用json呢,总体来说就是体积小速度快).但是前端对数组对象很'敏感',所以对PHP ...
- thinkphp5的Auth权限认证实战
thinkphp5的Auth权限认证实战 一.总结 一句话总结:基于角色的权限管理(真正做一遍,就会发现很简单,不然一直都是半懂不懂的) 角色 权限 真正做一遍,就会发现很简单,不然一直都是半懂不懂的 ...
- Can't push you anymore...
为什么我们不趁着年轻去冒险? 等我们准备好,也许都已经被生活冲淡了激情. Go to different places,to meet different people. To try, to fin ...