Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Variable increment / decrement by pressing the QkeyEvent button
Forum Updated to NodeBB v4.3 + New Features

Variable increment / decrement by pressing the QkeyEvent button

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 316 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.
  • C Offline
    C Offline
    Creatorczyk
    wrote on last edited by
    #1

    Hi,

    I created a class that aims to increment the variable "x" in the range 0-100 when pressing the "W" button on the keyboard. However, I would like the variable to slowly decrease to zero after releasing the button. During the increment / decrementation, I would like to introduce a delay. Does anyone know how to do it? My current code:

    void MoveControler::keyPressEvent(QKeyEvent *event)
    {
        try {
            if(event->key() ==Qt::Key_W){
               x+=1;
            }
        } catch (QString exception) {
         QMessageBox::about(nullptr, "Error", exception);
        }
    }
    
    ODБOïO 1 Reply Last reply
    0
    • C Creatorczyk

      Hi,

      I created a class that aims to increment the variable "x" in the range 0-100 when pressing the "W" button on the keyboard. However, I would like the variable to slowly decrease to zero after releasing the button. During the increment / decrementation, I would like to introduce a delay. Does anyone know how to do it? My current code:

      void MoveControler::keyPressEvent(QKeyEvent *event)
      {
          try {
              if(event->key() ==Qt::Key_W){
                 x+=1;
              }
          } catch (QString exception) {
           QMessageBox::about(nullptr, "Error", exception);
          }
      }
      
      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

      hi
      you can use QTimer

      1 Reply Last reply
      3

      • Login

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