Qt对话框布局调整

Qt 基础:

 在"main.cpp" 文件的开始部分加入以下头文件:

#include<Qsplitter> 

#include<QTextEdit> 

#include<QTextCodec> 

停靠窗口QDockWidget 类:

停靠窗口QDockWidget 类也是在应用程序中经常用到的,设置停靠窗口的一般流程如下。

(1) 创建一个QDockWidget 对象的停靠窗体。

(2) 设置此停靠窗体的属性,通常调用setFeaturesO及setAllowedAreas()两种方法。

(3) 新建一个要插入停靠窗体的控件,常用的有QListWidget 和QTextEdit 。

(4) 将控件插入停靠窗体,调用QDockWidget 的setWidget()方法。

(5) 使用addDockWidget()方法在MainWindow 中加入此停靠窗体。

第3 章

Qt5 布局管理:

本实例是采用编写代码的方式实现的,具体步骤如下。

(1) 新建Qt Widgets Application 

(详见1.3.1 节),项目名称为"DockWindows", 基类选择

"QMain Window", 类名命名为"DockWindows", 取消“创建界面“复选框的选中状态,如图

3.3 所示。

QMainWindow 主窗口的使用将在本书第5 章中详细介绍。

(2) Dock Windows 类中只有一个构造函数的声明。位于"dockwindows.h" 文件中,代码如下:

class DockWindows : public QMainWindow 

Q OBJECT 

public: 

DockWindows(QWidget *parent= 0); 

~DockWindows (); 

(3) 打开"dockwindows.cpp" 文件,

DockWindows 类构造函数实现窗口的初始化及功能实现,具体代码如下:

DockWindows::DockWindows(QWidget *parent) : QMainWindow(parent)

{

setWindowTitle(tr("DockWindows")); //设置主窗口的标题栏文字

QTextEdit *te = new QTextEdit(this); //定义一个QTextEdit 对象作为主窗口

te->setText(tr("Main Window")); 

te->setAlignment (Qt: :AlignCenter); 

setCentralWidget(te); 

//将此编辑框设为主窗口的中央窗体

//停靠窗口1

QDockWidget *dock = new QDockWidget(tr("DockWindowl"),this); 

//可移动

dock->setFeatures (QDockWidget:: DockWidgetMovable) ; //(a) 

dock->setAllowedAreas(Qt::LeftDockWidgetArealQt::RightDockWidgetArea); 

//(b) 

QTextEdit *tel = new QTextEdit (); 

tel->setText(tr("Windowl,The dock widget can be moved between docks by the

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

行者..................

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值