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. Intercetp system key (Alt+F4, Ctrl+Alt+Canc, ...) in a qtquick 2 app
Forum Update on Monday, May 27th 2025

Intercetp system key (Alt+F4, Ctrl+Alt+Canc, ...) in a qtquick 2 app

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 2 Posters 3.3k 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.
  • GedeoneCaneGrassoG Offline
    GedeoneCaneGrassoG Offline
    GedeoneCaneGrasso
    wrote on last edited by
    #1

    Hello,
    I'm new to Qt and Qt Quick, so I apologize if my question is silly and already has an answer, but after a lot of research, I have not found a solution that works.

    I'm developing an app for a info point totem. The app have 2 interfaces: a normal qt gui (a mainwindow), that run under all and is a service gui used for maintenance, and a QtQuick Gui, the real interface for the user that use the totem, loaded in fullscreen on the Qt Gui (I've used a QQmlApplicationEngine to load it).
    For security reason (it's a request that I have), I need to inhibit the key sequences that permit to close the QtQuick Gui, like Alt+F4, Ctrl+Alt+Canc, ... It's possible to close the QtQuick Gui only with a special key sequence (and this run correctly), and return to the Qt Gui service interface.
    I've tried to intercept this sequence from qml, using the Keys.onPressed with the focus set to true, but nothing: here I run the special sequence that intercept the Ctrl+w combination, but not the Alt+F4 or the Ctrl+Alt+Canc.
    I've tried overriding the eventFilter(QObject *obj, QEvent *event) function (applied to the main window or to the QQmlApplicationEngine), but nothing: the filter intercept the Ctrl + w, but nothing other.

    For now, I'm developing on a Windows 10 system, but probably will pass to a Debian or Kubuntu system.

    Do you have some idea? It's possible to intercept the system calls like the Ctrl+F4 and Ctrl+Alt+Canc?

    Thanks a lot

    1 Reply Last reply
    0
    • J Offline
      J Offline
      JordanHarris
      wrote on last edited by JordanHarris
      #2

      From looking at the documentation, you can use the close.accepted property in the callback of the closing signal in the Window type to prevent the window from closing.

      I haven't tried it, but maybe this could work.

      Window {
          id: win
          property bool closeKeysWereTriggered: false
          onClosed: {
              if (!closeKeysWereTriggered)  // If user defined close keys weren't triggered 
                  close.accepted = false    // force the window to stay open 
          } 
      
          Shortcut {
              sequence: "Ctrl+Q"
              onActivated: {
                  win.close();
                  closeKeysWereTriggered = true;
              } 
          }
      }
      
      1 Reply Last reply
      1
      • GedeoneCaneGrassoG Offline
        GedeoneCaneGrassoG Offline
        GedeoneCaneGrasso
        wrote on last edited by
        #3

        Hi JordanHarris,
        wonderful, it works! In this way I can block sequence like Alt+F4. Thanks a lot.
        I had to change from Window to ApplicationWindow, otherwise I could not use the onClosing method.

        Do you have any idea on how to block sequences like Alt+Tab or Ctrl+Alt+Canc?

        Thanks in advance

        1 Reply Last reply
        0
        • J Offline
          J Offline
          JordanHarris
          wrote on last edited by
          #4

          I don't think you can do that, but I don't really know. I'm not sure if that should even be possible. I don't know what Ctrl+Alt+Canc is, but I'm assuming it's like Ctrl+Alt+Del, and that should be available no matter where you are. Same with switching active application.

          GedeoneCaneGrassoG 1 Reply Last reply
          0
          • J JordanHarris

            I don't think you can do that, but I don't really know. I'm not sure if that should even be possible. I don't know what Ctrl+Alt+Canc is, but I'm assuming it's like Ctrl+Alt+Del, and that should be available no matter where you are. Same with switching active application.

            GedeoneCaneGrassoG Offline
            GedeoneCaneGrassoG Offline
            GedeoneCaneGrasso
            wrote on last edited by
            #5

            @JordanHarris
            Hi JordanHarris,
            ok, that's what I was afraid, I will try to solve in any other way.
            In the Italian keyboard layout, the Del button is called Canc, and in the rush to write I forgot it ...

            Thanks anyway!

            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