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. QPushbutton pressed
Qt 6.11 is out! See what's new in the release blog

QPushbutton pressed

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 1.2k 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.
  • Z Offline
    Z Offline
    Zunneh
    wrote on last edited by
    #1

    Hi guys , i want to move the circle with 4 Qpushbutton while they are pressed ( not only click ) , i tried signal pressed but didn't work (it work like simple click ) , i have ready in some forum that i have to use event , i tried this function but it didn't work ( i understand the phenomen but i don't know how to write it 0_1549960214300_Capture d’écran 2019-02-11 à 14.12.45.png 0_1549960223372_Capture d’écran 2019-02-11 à 16.39.10.png
    P.S: BTN_Up is the bouton up (QpushButton)
    Thanks

    my english is average, please use simple words and try to be the most explicit, thank you

    J.HilkJ D 2 Replies Last reply
    0
    • Z Zunneh

      Hi guys , i want to move the circle with 4 Qpushbutton while they are pressed ( not only click ) , i tried signal pressed but didn't work (it work like simple click ) , i have ready in some forum that i have to use event , i tried this function but it didn't work ( i understand the phenomen but i don't know how to write it 0_1549960214300_Capture d’écran 2019-02-11 à 14.12.45.png 0_1549960223372_Capture d’écran 2019-02-11 à 16.39.10.png
      P.S: BTN_Up is the bouton up (QpushButton)
      Thanks

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

      hi @Zunneh

      I fairly certain you'll need to use a QTimer here to regularly update your label position, while the button is pressed.

      MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent) {
          QTimer *timer = new QTimer(this);
          
          timer->setIntervall(1000) //1000ms
      
          connect(timer, &QTimer::timeout, this, &MainWindow:: updatePosition);
      
          connect(ui-> BTN_Up, &QPushButton::pressed, timer, QOverload<void>::of(&QTimer::start));
      connect(ui-> BTN_Up, &QPushButton::released, timer, &QTimer::stop);
      
      
      }
      
      
      void MainWindow::updatePosition() {
          if(ui->BTN_Up->isDown()) {
             currentY ++;
         } else {.....}
      
         ui->label->move(currentX, currentY);
      }
      

      untested Code, so no guaranties for typos and stuff ;-)


      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
      2
      • Z Zunneh

        Hi guys , i want to move the circle with 4 Qpushbutton while they are pressed ( not only click ) , i tried signal pressed but didn't work (it work like simple click ) , i have ready in some forum that i have to use event , i tried this function but it didn't work ( i understand the phenomen but i don't know how to write it 0_1549960214300_Capture d’écran 2019-02-11 à 14.12.45.png 0_1549960223372_Capture d’écran 2019-02-11 à 16.39.10.png
        P.S: BTN_Up is the bouton up (QpushButton)
        Thanks

        D Offline
        D Offline
        Devopia53
        wrote on last edited by
        #3

        @Zunneh

        like this:

        ui-> BTN_Up->setAutoRepeat(true);
        connect(ui->BTN_Up, &QPushButton::pressed, []{
                qDebug() << "Pressed!";
        });
        

        also use:
        autoRepeatDelay() and setAutoRepeatInterval()

        Z J.HilkJ 2 Replies Last reply
        7
        • D Devopia53

          @Zunneh

          like this:

          ui-> BTN_Up->setAutoRepeat(true);
          connect(ui->BTN_Up, &QPushButton::pressed, []{
                  qDebug() << "Pressed!";
          });
          

          also use:
          autoRepeatDelay() and setAutoRepeatInterval()

          Z Offline
          Z Offline
          Zunneh
          wrote on last edited by
          #4

          @Devopia53 Thank you guy you saved me :)
          @J-Hilk i tried @Devopia53 solution because it was easy and work perfect , i will try your solution , thank you guys

          my english is average, please use simple words and try to be the most explicit, thank you

          1 Reply Last reply
          0
          • D Devopia53

            @Zunneh

            like this:

            ui-> BTN_Up->setAutoRepeat(true);
            connect(ui->BTN_Up, &QPushButton::pressed, []{
                    qDebug() << "Pressed!";
            });
            

            also use:
            autoRepeatDelay() and setAutoRepeatInterval()

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

            @Devopia53 I total forgot autorepeat was a thing! thumbs up

            @Zunneh if your question is answered, don't forget to set the topic to solved, using the topic tools.


            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
            2

            • Login

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