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. Getting "Alt+F4" shortcut not working

Getting "Alt+F4" shortcut not working

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 2.3k 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.
  • D Offline
    D Offline
    deleted357
    wrote on last edited by deleted357
    #1

    Hi,

    I can't get "Alt + F4" shortcut to display a confirmation dialog. I can only prevent it from closing the window as shown below:

    ApplicationWindow {
        ...
        property bool closeKeysWereTriggered: false
        ...
        onClosing: {
            if (!closeKeysWereTriggered) {
                close.accepted = false;
        }
    
        Shortcut {
                sequence: "Escape"
                onActivated:  {
                    console.log("Escape shortcut");
                    exitDialog.open();
                }
    
                context: Qt.ApplicationShortcut
        }
        
        Shortcut {
                sequence: "Alt+F4"
                onActivated:  {
                    console.log("Alt+F4 shortcut");
                    exitDialog.open();
                }
    
                context: Qt.ApplicationShortcut
        }
        ...
        Dialog {
            id: exitDialog
        ...
            Button {
                id: yesButton
        ...
                onClicked: {
                    closeKeysWereTriggered = true;
                    window.close();
                }
        ...
    

    However, "Alt+F3" shortcut works.

    Any idea ?

    Best regards.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      AFAIK, ALT+F4 is not assignable as a shortcut (a bit like ALT+Tab) so you have to put the related logic in the onClosing method.

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

      1 Reply Last reply
      0
      • D Offline
        D Offline
        deleted357
        wrote on last edited by deleted357
        #3

        I found a solution in the code above:

        onClosing: {
                if (!closeKeysWereTriggered) {
                    close.accepted = false;
                    exitDialog.open();
                }
            }
        

        Now, the exit dialog is always displayed.

        Best regards.

        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