Solved Remove ? button from Windows MessageDialog?
-
Is there a way to get rid of the ? button in a Message Dialog in Qt Quick Controls 2 5.10?
In my situation, the ? button doesn't have any functionality. The default Mac dialog works as a sheet, so it doesn't have this issue, but Windows does.
-
@igor_stravinsky
I don't know anything about Quick Controls, but assuming your?
icon is the same thing I use (Python):# None of our dialogs support Windows context help "?" button self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint)
-
@igor_stravinsky said in Remove ? button from Windows MessageDialog?:
but Windows does.
It's strange. On my Windows 10 5.10.0 x64, the default
MessageDialog
does not show the '?' button:Nor does the
Dialog
type:Unfortunately, there seems to be no way to access the flags of the dialog window in QML ...
-
@Diracsbracket
Where are you seeing the version number as 10.5.10.0?I'm testing under Windows 10 Version 1803 (OS Build 17134.11)
-
@igor_stravinsky said in Remove ? button from Windows MessageDialog?:
Where are you seeing the version number as 10.5.10.0?
I meant Windows 10 (Qt) 5.10.0 ... I have also tried with Qt 5.10.1, and Qt 5.11.0, all are OK in that respect.
-
OK, now I understand the versioning nomenclature
In the file showing the dialog I've got
import QtQuick 2.10 import QtQuick.Controls 2.3 import QtQuick.Layouts 1.3 import QtWebView 1.1 import QtQuick.Dialogs 1.3
And am creating the MessageDialog with
MessageDialog { id: contactRepPopup title: "Datasheet not available" icon: StandardIcon.Warning text: "Contact your sales representative for a datasheet for this part" onAccepted: { contactRepPopup.close() } }
I'll start playing with the includes to see if that changes things.
-
@igor_stravinsky
This is how it shows on my system:Note: I call the dialog from within a
Window
element and it also works when invoked from within aApplicationWindow
element.#include <QGuiApplication> #include <QQmlApplicationEngine> int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); if (engine.rootObjects().isEmpty()) return -1; return app.exec(); }
import QtQuick 2.10 import QtQuick.Controls 2.3 import QtQuick.Layouts 1.3 import QtWebView 1.1 import QtQuick.Dialogs 1.3 Window { //ApplicationWindow { visible: true width: 640 height: 480 title: qsTr("Hello World") MessageDialog { id: contactRepPopup title: "Datasheet not available" icon: StandardIcon.Warning text: "Contact your sales representative for a datasheet for this part" onAccepted: { contactRepPopup.close() } Component.onCompleted: visible = true } }
-
@Diracsbracket Fascinating!
I wonder why your results and mine are different. Notice that in your dialog the icon and text have a darker background, whereas in mine, only the OK button has the darker background.
I'm running as a QApplication rather than a QGuiApplication. I had to make that change in order to use QtCharts. Could that be responsible for the different appearance?
-
@igor_stravinsky said in Remove ? button from Windows MessageDialog?:
Could that be responsible for the different appearance
Aha! Yes it seems you're right. In the example above I replaced
QGuiApplication
withQApplication
, and in that case I get:In that case however, if you use
Dialog
instead ofMessageDialog
, you don't have the "?", but you need to implement thecontentItem
of the dialog box yourself, which is of course very easy:
http://doc.qt.io/qt-5/qml-qtquick-dialogs-dialog.html#details
http://doc.qt.io/qt-5/qtquickdialogs-systemdialogs-customdialogs-qml.html -
There were a couple of changes in Qt regarding the infamous "What's this button":
Since Qt 5.8, the What's This button is not shown anymore for non-QWidget dialogs (see QTBUG-56239)
Since Qt 5.10, there's a global flag AA_DisableWindowContextHelpButton to disable the button by default in all dialogs.
-
@kkoehne said in Remove ? button from Windows MessageDialog?:
Since Qt 5.10, there's a global flag AA_DisableWindowContextHelpButton to disable the button by default in all dialogs.
Since that corresponds to my original suggestion of using
self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint)
I can't see why OP does not use that (the new global one if necessary/for preference). If you do not want the "Help button", why not just make the necessary call rather than agonising over all the differences/solutions across various Windows versions?
-
@kkoehne said in Remove ? button from Windows MessageDialog?:
Since Qt 5.10, there's a global flag AA_DisableWindowContextHelpButton to disable the button by default in all dialogs.
Awesome! Works beautifully, thanks!
int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_DisableWindowContextHelpButton); ... }
No need to use
Dialog
then.