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

时间:2019-02-19
本文章向大家介绍【Qt】弹出子窗口时禁用主窗口,主要包括【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::WindowModal 1 The 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::ApplicationModal 2 The window is modal to the application and blocks input to all windows.