Please nominate your Qt Champions for 2021!

How to disable default button from Dialog

  • Hey,
    I have a simple qml file like this:

    Item {
        signal qmlYesSig(string msg)
        signal qmlNoSig (string msg)
        Dialog {
            id: dialog
            visible: true
            Button {
                text: "No"
                onClicked: qmlNoSig("NO")
                // dialog.close()
            Button {
                text: "Yes"
                onClicked: qmlYesSig("YES")

    By default it add an "ok" button and i don't know how to remove it.
    On the internet i have found something about this but only for controls declare in C++, not for qml.
    Is possible to dezactivate the default button?

  • @Lucian What are the import statements in your file? There are three different Dialog types in QML.

  • Hey @Eeli-K ,
    I'm sorry but i didn't understand your question :D

  • @Lucian The import statements in your qml file reveal what Dialog type you are using. If you open Index in the Qt Creator Help and look for Dialog you get three different Dialog types (in Qt 5.8). It's easier to answer to your question if we know which one of the three Dialogs you are using.

  • Right, sorry .
    Here are my imports

    import QtQuick 2.3
    import QtQuick.Window 2.0
    import QtQuick.Controls 1.2
    import QtQuick.Dialogs 1.2

  • @Adrian.Aioanei Then it's from QtQuick.Dialogs 1.2. Just look at the documentation and the property contentItem. It replaces the whole content, including the default buttons, and you can declare your own buttons. On the other hand the standardButtons property does what you want and maybe more - I don't know why you would want to declare your own "Yes" and "No" buttons and new signals while the standard ones are available.

  • Hey @Eeli-K
    My interface has a different type of button and the default button from dialog are old and ugly.
    The contentitem doesn't seem to help me, if you took about this from here Doc Qt

  • @Adrian.Aioanei Why it doesn't help to remove the default buttons? " is possible to bind contentItem to a custom Item, in which case there will be no buttons, no margins, and the custom content will fill the whole dialog."

  • This post is deleted!

Log in to reply