MessageDialog hidden behind main window :-(



  • Hi,

    apologies if this is the 100th repetition of an old question but I'm new to Qt and my google skills didn't help to turn up a working solution. What I'm trying to do is to display a MessageDialog (from QtQuick Controls) before the main window is shown/accessible. Initially, I tried to show the Message Dialog as standalone using code in main.cpp but I never got that working so decided to use another, qml based, approach:

    Blankout everything in the main window when it loads.

    Display the dialog from inside the main window.

    If the user clicks 'Ok' show all the other stuff in the main window.

    I got that working reasonably well except that the Message Dialog opens behind the main window. That is quite annoying because the users will have to figure out why they can't do anything in the main window but sooner or later they'll find the dialog hidden behind the main window. However, if the main window starts in fullscreen mode then my users will have a real problem because the dialog is still hidden behind the main window.

    Here's my sample code:
    MyDialog.qml:
    @import QtQuick 2.0
    import QtQuick.Dialogs 1.1

    MessageDialog {
    id: myDialog
    icon: StandardIcon.Warning
    modality: Qt.ApplicationModal
    title: "myDialog"
    text: "some dialog"
    standardButtons: StandardButton.Abort | StandardButton.Ok
    }@

    main.qml:
    @import QtQuick 2.0
    import QtQuick.Controls 1.1

    ApplicationWindow {
    id: root
    width: 1000
    height: 750
    color: "#333333"

    /** blockScreen:  Covers almost everything until the user clicked 'Ok' 
     *                in the dialog.
     *  myDialog:     This is the actual dialog. If the user clicks 'Ok' 
     *                the other contents will be revealed, otherwise the 
     *                program quits.
     *  dialogPassed: This variable registers whether the user has already 
     *                seen myDialog and clicked 'Ok' or whether the user 
     *                still has to see the dialog.
     *  onVisibilityChanged: Everytime the 
     *                application is launched, minimised or maximised this 
     *                signal triggers. The first time that it triggers is 
     *                necessarily when the application is being launched 
     *                and that's when myDialog needs to be displayed. 
     *                Thanks to dialogPassed all the other times it's 
     *                triggered do not matter.
     */
    Rectangle {
        id: blockScreen
        anchors.fill: parent
        color: "#ff0000"
    }
    
    MyDialog {
        id: myDialog
        onAccepted: {
            blockScreen.visible = false
        }
        onRejected: {
            Qt.quit()
        }
    }
    
    property bool dialogPassed: false
    
    onVisibilityChanged: {
        if (!dialogPassed) {
            myDialog.open()
            dialogPassed = true
        }
    }
    

    }@

    main.cpp:
    @#include <QtGui/QGuiApplication>
    #include <QQmlEngine>
    #include <QQmlComponent>
    #include <QQuickWindow>
    #include <QObject>

    int main(int argc, char *argv[])
    {
    // Setup the GUI:
    QGuiApplication app(argc, argv);
    QQmlEngine *engine = new QQmlEngine();
    app.connect(engine, SIGNAL(quit()), SLOT(quit()));
    QQmlComponent *component = new QQmlComponent(engine);
    component->loadUrl(QUrl("qml/bugDemo/main.qml"));
    if (!component->isReady()) {
    qWarning("%s", qPrintable(component->errorString()));
    return(-1);
    }

    // Start the GUI:
    QObject *topLevel = component->create();
    QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);
    window->show();
    return app.exec();
    

    }@

    And that's a screenshot of what I get:
    !http://i43.tinypic.com/10d5qg5.png(Screenshot of what I get)!
    As you can see the MessageDialog is hidden behind the window.

    Where is my mistake? Is there a better solution to do this?

    Thanks,
    Jack



  • P.S. I'm running it on Debian Squeeze with Qt 5.2.0, QtCreator 3.0.0 and gcc version 4.7.2, x86 64bit architecture.


Log in to reply
 

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