QPushbutton pressed
-
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
P.S: BTN_Up is the bouton up (QpushButton)
Thanks -
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 ;-)
-
@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 -
@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.