Qt: How to give focus to a modeless QDialog created from the main window when the main window is blocked by a modal QDialog

后端 未结 2 1869
北海茫月
北海茫月 2021-01-14 14:12

In my Qt Application I\'m facing the following scenario: When a specific event is raised I show a modeless QDialog which asks the user for a confirmation. The D

相关标签:
2条回答
  • 2021-01-14 14:27

    When modal dialog to be activated (about to show) you may try change parent of modeless dialog to this modal dialog. As modeless dialog will have the modal dialog as parent then there is a chance to have it on top. Still it may also depend on platform.

    Of course ideally to avoid such situations

    0 讨论(0)
  • 2021-01-14 14:30

    I found a working solution:

    void MainWindow::TimerElapsed()
    {
        QWidget *pwidget=NULL;
        m_qTimer.stop();
        foreach(pwidget,QApplication::topLevelWidgets())
        {
            if ((pwidget->isWindow())&&(pwidget->isModal()))
            {
                m_pModeless->setParent(pwidget);
            }
        }
        if (pwidget==NULL)
        {
            m_pModeless->setParent(this);
        }
        m_pModeless->show();
        m_pModeless->activateWindow();
        m_pModeless->raise();
        m_pModeless->setFocus();
    }
    
    0 讨论(0)
提交回复
热议问题