[Solved] Custom QtQuick MessageDialog



  • Greetings,

    I have a simple question: is there a way to make a custom MessageDialog in QtQuick?

    The actual problem I seem to have is that when the property standardButtons gets more than one value (for example StandardButton.Abort | StandardButton.Retry at the same time) I get the error setGeometry: Attempt to set a size (...) violating the constraints (...) on window QQuickWindow/''. (which I assume is a not yet fixed bug, as far as I could find)

    And besides, I'd like to tweak the visuals a little bit.



  • I think the fastest way is to just make your own dialog from scratch, with QML that should be very easy?



  • That's true, that crossed my mind, but a MessageDialog has some properties I am not sure I can implement: such as Modality and the fact that the Dialog is a complete separate window, that can be maximized, minimized and closed with the X button



  • I don't know but but on mobile devices like android and iOS you cannot have multiple windows anyway, so you just have to use an overlay in QML.

    Does the default MessageDialog work on mobile devices? I've tried the FileDialog that works kinda, but looks and works terrible on android xD

    IF you try to open an actual second window the app will crash in most cases.



  • So what would be a possible workaround to a FileDialog?



  • I mean the FileDialog works don't get me wrong, but the name filter's are not working (at least with the QML dialog) and it doesn't look that good in my opinion, you have to see it yourself. On a desktop computer it uses the native file dialog as far as I know, so no problems there.

    I guess it depends what you want to do and if you also want to target mobile platforms you can't use multiple windows anyways.



  • OK, I think I have found a possible solution to my Problem:

    @import QtQuick.Window 2.0
    ApplicationWindow {

        // some stuff
    
        Window {
                visible: true
                modality: Qt.ApplicationModal
                width: 600
                height: 400
    
                //implement buttons and logic
          }@
    

    }



  • Your solution is not a solution but a workaround. The original bug is serious. It practically makes the MessageDialog from QtQuick unusable.

    I get the very same error you reported with "violating the constraints (…) on window QQuickWindow". The dialog is "freezing" and I did not find a solution for it. I want to take benefit of standardButtons feature, I only need Yes/No confirmation and I cannot use MessageDialog.

    I don't care about layout/fonts etc, is there an alternative for a simple Yes/No confirmation dialog in QtQuick?



  • few minutes after my previous post, I got a solution/workaround for it.
    It doesn't work if you define the standardButtons inside the MessageDialog like:

    @ MessageDialog {
    id: messageDialogOnRemove
    modality: Qt.WindowModal
    // ... other stuff here..
    standardButtons: StandardButton.Yes | StandardButton.No
    }@

    but it works if you avoid defining the standardButtons in the declaration above and put it just before you want to display it, like:

    @messageDialogOnRemove.standardButtons = StandardButton.Yes | StandardButton.No
    messageDialogOnRemove.show()@

    Hope this helps someone.


Log in to reply
 

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