Sven van den Boogaart
Sven van den Boogaart

Reputation: 12327

QML hide question mark from messagedialog

Is it possible to hide the question mark from a qml messageDialog? My dialog:

MessageDialog {
    id: messageDialog
    text: "Do you want to remove the probe from the list"
    property int index: -1


    onAccepted: {
        //onAccepted is triggered twice, but we onyl want to remove the item once
        if(!removedItem){
            removedItem = true;
            applicationWindow.removeProbe(index)
            messageDialog.close()
        }
    }
}

The result:

enter image description here

The question button is leading to nowhere.

Upvotes: 1

Views: 735

Answers (1)

Maxim Paperno
Maxim Paperno

Reputation: 4869

UPDATE: I found this application attribute which looks promising. Seems to work for me for both C++ dialogs and QML MessageDialog.

Qt::AA_DisableWindowContextHelpButton

From the documentation (emphasis mine):

Disables the WindowContextHelpButtonHint by default on Qt::Sheet and Qt::Dialog widgets. This hides the ? button on Windows, which only makes sense if you use QWhatsThis functionality. This value was added in Qt 5.10. In Qt 6, WindowContextHelpButtonHint will not be set by default.

I set it in main() e.g.:

QApplication::setAttribute(Qt::AA_DisableWindowContextHelpButton);
QApplication app(argc, argv);

Incidentally, I found that MessageDialog created from pure-QML Window or ApplicationWindow (loaded directly as a Component into a QmlEngine and displayed that way) doesn't have the context help button. But one from inside a QQuickView does. So if using only QGuiApplication then this shouldn't be needed.

ORIGINAL:

There is no API available in the QtQuick.Dialogs version of MessageDialog to control the window flags. (QML can be frustrating like that, IMHO.)

The Qt Labs version does have a way to specify window flags (in the base Dialog type). So to exclude the ? one would remove the Qt::WindowContextHelpButtonHint from default flags or set your own flags specifically.

Something like this should work (not tested in QML but this is essentially what I do for QDialog):

import Qt.labs.platform 1.1
MessageDialog {
  flags: Qt.Dialog | Qt.CustomizeWindowHint | Qt.WindowTitleHint | Qt.WindowCloseButtonHint | Qt.WindowSystemMenuHint
}

But note that the Labs version comes with its own caveats as described in their docs.

Upvotes: 4

Related Questions