Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. German
  4. QShortcut release
Forum Updated to NodeBB v4.3 + New Features

QShortcut release

Scheduled Pinned Locked Moved Solved German
5 Posts 3 Posters 958 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.
  • J Offline
    J Offline
    Jakobm789
    wrote on last edited by
    #1

    Moin,
    ich verwende in einem Programm ein QShortcut und würde gerne eine Funktion ausführen, wenn dieses Shortcut nicht mehr aktiv ist. Ist das in irgendeiner Form möglich? Habe auch schon von keypressevents gelesen, habe aber nichts genaueres herausfinden können. Ich würde die Funktionen gerne in etwa so verwenden:
    test.cpp:

    new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_D), this, SLOT(shortcut_pressed()));
    
    void test::shortcut_pressed()
    }
            D=1;
    }
    
    void test::shortcut_released()
    {
            D=0;
    }
    

    Also soll quasi während der Shortcut betätigt ist D=1 sein und wenn der Shortcut wieder losgelassen wird D=0.
    Vielen Dank für eure Hilfe!

    J.HilkJ 1 Reply Last reply
    0
    • J Jakobm789

      Moin,
      ich verwende in einem Programm ein QShortcut und würde gerne eine Funktion ausführen, wenn dieses Shortcut nicht mehr aktiv ist. Ist das in irgendeiner Form möglich? Habe auch schon von keypressevents gelesen, habe aber nichts genaueres herausfinden können. Ich würde die Funktionen gerne in etwa so verwenden:
      test.cpp:

      new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_D), this, SLOT(shortcut_pressed()));
      
      void test::shortcut_pressed()
      }
              D=1;
      }
      
      void test::shortcut_released()
      {
              D=0;
      }
      

      Also soll quasi während der Shortcut betätigt ist D=1 sein und wenn der Shortcut wieder losgelassen wird D=0.
      Vielen Dank für eure Hilfe!

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by J.Hilk
      #2

      Hi @Jakobm789

      ich hab leider nicht soviel Erfahrung mit QShortcut, aber, wenn man sich die Dokumentation anschaut, findet man den Eintrag über autorepeat:

      This property holds whether the shortcut can auto repeat
      
      If true, the shortcut will auto repeat when the keyboard shortcut combination is held down, provided that keyboard auto repeat is enabled on the system. The default value is true.
      

      Das, in Kombination mit einem QTimer, der ausläuft, wenn er nicht durch das signal neu gestartet wird, sollte dein Problem lösen


      so in etwa:

      int main (int argc, char *argv[])
      {
      
          QApplication app(argc, argv);
      
          QLabel w ("P not pressed");
          w.resize(200,200);
          w.show();
      
          QShortcut sh(&w);
          sh.setKey(Qt::CTRL + Qt::Key_P);
      
          QTimer tReset;
          QObject::connect(&tReset, &QTimer::timeout, &w, [&w, &tReset]()->void{
               tReset.stop();
               w.setText("P not pressed");
          });
      
          QObject::connect(&sh, &QShortcut::activated, &w, [&w, &tReset]()->void{
              w.setText("P is pressed");
              tReset.start(800);
          });
      
      
          return  app.exec();
      }
      

      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.

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

        Hi @Jakobm789

        ich hab leider nicht soviel Erfahrung mit QShortcut, aber, wenn man sich die Dokumentation anschaut, findet man den Eintrag über autorepeat:

        This property holds whether the shortcut can auto repeat
        
        If true, the shortcut will auto repeat when the keyboard shortcut combination is held down, provided that keyboard auto repeat is enabled on the system. The default value is true.
        

        Das, in Kombination mit einem QTimer, der ausläuft, wenn er nicht durch das signal neu gestartet wird, sollte dein Problem lösen


        so in etwa:

        int main (int argc, char *argv[])
        {
        
            QApplication app(argc, argv);
        
            QLabel w ("P not pressed");
            w.resize(200,200);
            w.show();
        
            QShortcut sh(&w);
            sh.setKey(Qt::CTRL + Qt::Key_P);
        
            QTimer tReset;
            QObject::connect(&tReset, &QTimer::timeout, &w, [&w, &tReset]()->void{
                 tReset.stop();
                 w.setText("P not pressed");
            });
        
            QObject::connect(&sh, &QShortcut::activated, &w, [&w, &tReset]()->void{
                w.setText("P is pressed");
                tReset.start(800);
            });
        
        
            return  app.exec();
        }
        
        J Offline
        J Offline
        Jakobm789
        wrote on last edited by
        #3

        @J-Hilk Danke für deine Antwort, aber ich verstehe nicht ganz wie ich das auf meinen Fall anwenden soll, da schon bei der Initialisierung ein Fehler ausgegeben wird...

        jsulmJ 1 Reply Last reply
        0
        • J Jakobm789

          @J-Hilk Danke für deine Antwort, aber ich verstehe nicht ganz wie ich das auf meinen Fall anwenden soll, da schon bei der Initialisierung ein Fehler ausgegeben wird...

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Jakobm789 said in QShortcut release:

          ein Fehler ausgegeben wird...

          welcher?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          J 1 Reply Last reply
          0
          • jsulmJ jsulm

            @Jakobm789 said in QShortcut release:

            ein Fehler ausgegeben wird...

            welcher?

            J Offline
            J Offline
            Jakobm789
            wrote on last edited by
            #5

            @jsulm Okay funktioniert doch, mein Fehler🤦‍♂️.
            Vielen Dank euch beiden!

            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