Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML MessageDialog on macOS/OSX

QML MessageDialog on macOS/OSX

Scheduled Pinned Locked Moved Solved QML and Qt Quick
10 Posts 3 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    VRHans
    wrote on 5 Aug 2018, 01:51 last edited by
    #1

    On Windows and Linux the message dialog looks just fine; however on macOS it looks terrible (e.g. there's no title bar) - which I presume means it's using the fallback qml implementation (which I can customize.)

    On macOS does the qml engine always use the qml implementation or is there some characteristic of my application which is preventing the native message dialog/box from being used?

    Thanks!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 5 Aug 2018, 21:37 last edited by SGaist 8 May 2018, 21:38
      #2

      Hi,

      Can you post a picture of what you get exactly ?
      What version of Qt are you using ?
      What exact version of macOS are you running ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      V 1 Reply Last reply 6 Aug 2018, 16:49
      0
      • S SGaist
        5 Aug 2018, 21:37

        Hi,

        Can you post a picture of what you get exactly ?
        What version of Qt are you using ?
        What exact version of macOS are you running ?

        V Offline
        V Offline
        VRHans
        wrote on 6 Aug 2018, 16:49 last edited by
        #3

        @SGaist Sorry it took so long to reply:

        macOS version: 10.13.6 (High Sierra)
        Qt Version: 5.11.1

        This is the code I use to reproduce this trivially:

        import QtQuick 2.11
        import QtQuick.Window 2.11
        import QtQuick.Controls 1.4
        import QtQuick.Dialogs 1.3
        
        
        Window {
        	visible: true
        	width: 640
        	height: 480
        	title: qsTr("Hello World")
        
        	MessageDialog {
        		id: messageDialog
        		title: "May I have your attention please"
        		text: "It's so cool that you are using Qt Quick."
        		onAccepted: {
        			console.log("And of course you could only agree.")
        			Qt.quit()
        		}
        	}
        
        	Button {
        		text: "Button"
        
        		onClicked: {
        			messageDialog.open();
        		}
        	}
        }
        

        The results look like this:
        0_1533574109257_macOS_messagedialog.png

        1 Reply Last reply
        0
        • S Offline
          S Offline
          shaan7
          wrote on 6 Aug 2018, 17:10 last edited by
          #4

          That looks right to me, Mac apps normally show child message boxes like this. If you want a separate window, then don't make the MessageBox a child of your Window, like this-

          Item {
              Window {
              }
          
              MessageBox {
              }
          }
          
          V 2 Replies Last reply 6 Aug 2018, 17:20
          1
          • S shaan7
            6 Aug 2018, 17:10

            That looks right to me, Mac apps normally show child message boxes like this. If you want a separate window, then don't make the MessageBox a child of your Window, like this-

            Item {
                Window {
                }
            
                MessageBox {
                }
            }
            
            V Offline
            V Offline
            VRHans
            wrote on 6 Aug 2018, 17:20 last edited by
            #5

            @shaan7 That change makes the simple sample above non-functional. It runs but the main window is not visible.

            S 1 Reply Last reply 6 Aug 2018, 17:42
            0
            • S shaan7
              6 Aug 2018, 17:10

              That looks right to me, Mac apps normally show child message boxes like this. If you want a separate window, then don't make the MessageBox a child of your Window, like this-

              Item {
                  Window {
                  }
              
                  MessageBox {
                  }
              }
              
              V Offline
              V Offline
              VRHans
              wrote on 6 Aug 2018, 17:27 last edited by
              #6

              @shaan7 - also, creating a very quick sample XCode app NSAlert doesn't seem to exhibit this limitation.

              macOS apps show child dialogs without a titlebar, but not message boxes.

              1 Reply Last reply
              0
              • V VRHans
                6 Aug 2018, 17:20

                @shaan7 That change makes the simple sample above non-functional. It runs but the main window is not visible.

                S Offline
                S Offline
                shaan7
                wrote on 6 Aug 2018, 17:42 last edited by
                #7

                @VRHans Ah I didn't complete the example, you'll still need to set visible: true and/or Component.onCompleted: show() on the Window element for it to be visible. (I don't use a Mac anymore so can't really verify if that works, just pointing out what I remember).

                import QtQuick 2.11
                import QtQuick.Controls 2.3
                import QtQuick.Window 2.11
                import QtQuick.Dialogs 1.3
                
                Item {
                    Window {
                        width: 640
                        height: 480
                
                        Button {
                            text: "Button"
                
                            onClicked: messageDialog.open()
                        }
                
                        Component.onCompleted: show()
                    }
                
                    MessageDialog {
                        id: messageDialog
                        title: "May I have your attention please"
                        text: "It's so cool that you are using Qt Quick."
                        onAccepted: {
                            console.log("And of course you could only agree.")
                            Qt.quit()
                        }
                    }
                }
                
                V 1 Reply Last reply 6 Aug 2018, 17:46
                2
                • S shaan7
                  6 Aug 2018, 17:42

                  @VRHans Ah I didn't complete the example, you'll still need to set visible: true and/or Component.onCompleted: show() on the Window element for it to be visible. (I don't use a Mac anymore so can't really verify if that works, just pointing out what I remember).

                  import QtQuick 2.11
                  import QtQuick.Controls 2.3
                  import QtQuick.Window 2.11
                  import QtQuick.Dialogs 1.3
                  
                  Item {
                      Window {
                          width: 640
                          height: 480
                  
                          Button {
                              text: "Button"
                  
                              onClicked: messageDialog.open()
                          }
                  
                          Component.onCompleted: show()
                      }
                  
                      MessageDialog {
                          id: messageDialog
                          title: "May I have your attention please"
                          text: "It's so cool that you are using Qt Quick."
                          onAccepted: {
                              console.log("And of course you could only agree.")
                              Qt.quit()
                          }
                      }
                  }
                  
                  V Offline
                  V Offline
                  VRHans
                  wrote on 6 Aug 2018, 17:46 last edited by
                  #8

                  @shaan7 said in QML MessageDialog on macOS/OSX:

                  Component.onCompleted: show()

                  That worked - cheers. It does mean that all of my qml code (I have a plugin based system and those plugins need to be able to generate message boxes) will need to make use of a global root based (outside the hosting window) messagedialog.

                  The plugins just won't be able to use messagedialog directly (but that's a stipulation I can probably live with.)

                  Thanks!

                  S 1 Reply Last reply 6 Aug 2018, 18:13
                  0
                  • V VRHans
                    6 Aug 2018, 17:46

                    @shaan7 said in QML MessageDialog on macOS/OSX:

                    Component.onCompleted: show()

                    That worked - cheers. It does mean that all of my qml code (I have a plugin based system and those plugins need to be able to generate message boxes) will need to make use of a global root based (outside the hosting window) messagedialog.

                    The plugins just won't be able to use messagedialog directly (but that's a stipulation I can probably live with.)

                    Thanks!

                    S Offline
                    S Offline
                    shaan7
                    wrote on 6 Aug 2018, 18:13 last edited by
                    #9

                    @VRHans said in QML MessageDialog on macOS/OSX:

                    The plugins just won't be able to use messagedialog directly

                    Well if you do this in the root Item-

                    Item {
                        property alias messageDialog: messageDialog
                    

                    then messageDialog should become available to the Window and all its children's contexts (even the ones that you load dynamically afaik).

                    V 1 Reply Last reply 6 Aug 2018, 18:21
                    0
                    • S shaan7
                      6 Aug 2018, 18:13

                      @VRHans said in QML MessageDialog on macOS/OSX:

                      The plugins just won't be able to use messagedialog directly

                      Well if you do this in the root Item-

                      Item {
                          property alias messageDialog: messageDialog
                      

                      then messageDialog should become available to the Window and all its children's contexts (even the ones that you load dynamically afaik).

                      V Offline
                      V Offline
                      VRHans
                      wrote on 6 Aug 2018, 18:21 last edited by
                      #10

                      @shaan7 - yes, but that means changes to the plugin hosting qml code could break plugins, so I'll be abstracting that behind an function/method.

                      1 Reply Last reply
                      0

                      1/10

                      5 Aug 2018, 01:51

                      • Login

                      • Login or register to search.
                      1 out of 10
                      • First post
                        1/10
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved