【Qt】弹出子窗口时禁用主窗口

转载: https://blog.csdn.net/kaspar1992/article/details/75984022

 

子窗口名:userManagerDialog
Qt::WindowFlags flags = Qt::Dialog;
 userManagerDialog->setWindowFlags(flags);
 
弹出子窗口时禁用主窗口
userManagerDialog->setWindowModality(Qt::ApplicationModal); //阻塞除当前窗体之外的所有的窗体

关于setWindowFlag的解释:

Window flags are a combination of a type (e.g. Qt::Dialog) and zero or more hints to the window system (e.g.Qt::FramelessWindowHint).

If the widget had type Qt::Widget or Qt::SubWindow and becomes a window (Qt::Window,Qt::Dialog, etc.), it is put at position (0, 0) on the desktop. If the widget is a window and becomes aQt::Widget orQt::SubWindow, it is put at position (0, 0) relative to its parent widget.

Note: This function calls setParent() when changing the flags for a window, causing the widget to be hidden. You must callshow() to make the widget visible again..

Access functions:

Qt::WindowFlags

windowFlags() const

void

setWindowFlags(Qt::WindowFlags type)

关于setWindowModality的解释:

This property holds which windows are blocked by the modal widget.

This property only makes sense for windows. A modal widget prevents widgets in other windows from getting input. The value of this property controls which windows are blocked when the widget is visible. Changing this property while the window is visible has no effect; you must hide() the widget first, thenshow() it again.

By default, this property is Qt::NonModal.

This property was introduced in Qt 4.1.

Access functions:

Qt::WindowModality

windowModality() const

void

setWindowModality(Qt::WindowModalitywindowModality)

This enum specifies the behavior of a modal window. A modal window is one that blocks input to other windows. Note that windows that are children of a modal window are not blocked.

The values are:

Constant

Value

Description

Qt::NonModal

0

The window is not modal and does not block input to other windows.

Qt::WindowModal1The window is modal to a single window hierarchy and blocks input to its parent window, all grandparent windows, and all siblings of its parent and grandparent windows.
Qt::ApplicationModal2The window is modal to the application and blocks input to all windows.

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值