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 1892
北海茫月
北海茫月 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: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();
    }
    

提交回复
热议问题