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. MessageDialog responsive to keyboard events.

MessageDialog responsive to keyboard events.

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 2 Posters 661 Views 1 Watching
  • 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.
  • EmilieGE Offline
    EmilieGE Offline
    EmilieG
    wrote on last edited by
    #1

    Hello,

    Is there a way to have a MessageDialog responsive to keyboard events ?
    I tried to catch a return key signal (like the following snippet ) but it's not working.

    MessageDialog {
    
        id: failed_popup
        property string message : failed_popup.text
        property string errorTitle : failed_popup.title
        property alias icon : failed_popup.icon
        title: errorTitle
        icon: StandardIcon.Warning
        standardButtons: StandardButton.Ok
        text: message
    
        Keys.onReturnPressed: {
            console.log(" Return pressed ")
            accepted();
        }
    }
    

    I know I could use another QML component like window but I was expected this to be working in MessageDialog directly as I don't need anything more complicated..
    Am I missing something ?

    1 Reply Last reply
    0
    • J.HilkJ Online
      J.HilkJ Online
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @EmilieG that should work, are you sure you're pressing return and not enter ? that can vary from region to region and keyboard to keyboard and os to os

      also try forcing active focus on the MessageDialog

      activeFocus:true

      because maybe another component (for example the button) has active focus after displaying the Dialog


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      EmilieGE 1 Reply Last reply
      0
      • J.HilkJ J.Hilk

        @EmilieG that should work, are you sure you're pressing return and not enter ? that can vary from region to region and keyboard to keyboard and os to os

        also try forcing active focus on the MessageDialog

        activeFocus:true

        because maybe another component (for example the button) has active focus after displaying the Dialog

        EmilieGE Offline
        EmilieGE Offline
        EmilieG
        wrote on last edited by
        #3

        @J-Hilk Thanks for your answer. There is no activeFocus or focus property for the MessageDialog, so it's not compiling..

        J.HilkJ 1 Reply Last reply
        0
        • EmilieGE EmilieG

          @J-Hilk Thanks for your answer. There is no activeFocus or focus property for the MessageDialog, so it's not compiling..

          J.HilkJ Online
          J.HilkJ Online
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @EmilieG
          ok, I tried your example code and I actually get the following message:

          Could not attach Keys property to: DefaultMessageDialog_QMLTYPE_35_QML_37(0x7fcb04c5fe40) is not an Item

          so, you can't catch the key event 🤷‍♂️

          You could possibly install an eventFilter in main.cpp that should work


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          0

          • Login

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