[Interest] Qml MessageDialog not centered over window

Murphy, Sean smurphy at walbro.com
Sun Sep 24 02:00:01 CEST 2017


I'm not sure if this is a bug, or if I'm doing something wrong, but I'm trying to display a Qml dialog when an error occurs and it's coming up centered on my monitor, not centered over the application.

Relevant code:
Window {
    MessageDialog {
        id: errorDialog
        objectName: "errorDialog"
        title: "Error"
        text: ""
    }
    Item {
        id: functionItem
        objectName: "item"

        function receivedError(text) {
            console.log("Error received: " + text);
            errorDialog.text = "Error, " + text;
            errorDialog.open();
        }
    }
}

Then on the C++ side I do 
    QObject::connect(feed, SIGNAL(sigError(QVariant)),
        cv, SLOT(receivedError (QVariant)));

The code works - whenever I emit sigError(errorString), the Qml function is called and the dialog opens with the correct message text. It's just that the position of the dialog is wrong.

This is occurring on Windows 7, Qt 5.9.1. I'm running on a dual monitor setup, and the dialog is showing up centered on the same monitor (left) that the application is running on, not centered across my entire desktop.

If this were a pure C++ application, I would say that the dialog isn't parented, but at least from this documentation, http://doc.qt.io/qt-5/qml-qtquick-dialogs-messagedialog.html, I think I'm parenting it correctly on the Qml side. The documentation states that " A MessageDialog window is automatically transient for its parent window. So whether you declare the dialog inside an Item or inside a Window, the dialog will appear centered over the window containing the item, or over the Window that you declared."

Sean



More information about the Interest mailing list