开发者

Main application window and a dialog interaction in Qt

Good day!

Have a problem: main window (MyApp for example) works in background (behind all other windows or in tray), not necessary to show it without need. After some peri开发者_StackOverflowod of time some reminding StayOnTop dialog appears (having parent = 0, to be not tied to main window) and asks for some user interactions. After dialog closes I’d like to keep an application window user currently working with active, and user continue do his job not switching to MyApp. However, instead of above behaviour, main MyApp window appears and user forces to switch back to his window (job) – inconvenient.

How to prevent MyApp main window appearing after closing the dialog? Need to install some event filter or access OS API? Problem exists in Mac, Windows, Linux.


You could try to re-implement the main window's showEvent and ignore that event, in case other windows are visible.

void main_window::showEvent( QShowEvent* e )
{
    if( /*one or more of its children are visible */ )
    {
        // nothing to do
    }
    else
    {
        QMainWindow::showEvent( e );
    }
}


Maybe just try invoking hide method after dialog call? Other possibility - try setting this: http://doc.qt.io/qt-4.8/qwidget.html#windowFlags-prop to Qt::Popup.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜