子窗体显示的时候怎么让父窗体阻塞并且子窗体可以任意移动?



  • 试过setWindowFlags(Qt::FramelessWindowHint)但是效果并不是我想要的



  • @flydragon hi, friend. welcome.

    you can find some helpful information from qt help manual.

    int QDialog::exec()
    Shows the dialog as a modal dialog, blocking until the user closes it. The function returns a DialogCode result.
    If the dialog is application modal, users cannot interact with any other window in the same application until they close the dialog. If the dialog is window modal, only interaction with the parent window is blocked while the dialog is open. By default, the dialog is application modal.

    like below code snippet:

    /**.....*/
    QDialog dlg(parent);
    dlg.exec();
    /**.....*/
    


  • @flydragon 朋友,你好,欢迎。

    我再使用中文回复一下吧, 毕竟在中文论坛里面;

    首先,窗体的显示分为两种模式,非模态和模态。 您的需求就属于模态显示。 子窗体显示在父窗体上面,阻塞父窗体的行为。

    当您查看Qt的帮助文档的时候,您就会看到以下内容:

    int QDialog::exec()
    Shows the dialog as a modal dialog, blocking until the user closes it. The function returns a DialogCode result.
    If the dialog is application modal, users cannot interact with any other window in the same application until they close the dialog. If the dialog is window modal, only interaction with the parent window is blocked while the dialog is open. By default, the dialog is application modal.

    exe()这个函数,就会使窗体进行模态的显示,使这个窗体进入Qt的事件循环。直到这个窗体关闭。它的父窗体才可以活动。

    简单的代码片段:

    /**.....*/
    QDialog dlg(parent); ///记得把父窗口的指针传递给子窗体
    dlg.exec();
    /**.....*/
    


  • 窗口类都有一个成员函数可以设置窗口是否模态,大概语法是setWindowModality(Qt::NonModal | Qt::Modal),
    因为默认就是模态的,所以不用自己设置。


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.