[SOLVED] Simulate input for a QMainWindow



  • Hello,

    I would like to simulate mouse/key input for a QMainWindow.
    I was trying with this:

    void MainWindow::SltButtonClicked()
    {
    	QPointF pos(ui.pushButton_2->pos());
    
    	QObject* rec = this; // ui.centralWidget // ui.pushButton_2 // QApplication::instance()
    
    	QApplication::postEvent(rec, new QMouseEvent(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier));
    	QApplication::postEvent(rec, new QMouseEvent(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier));
    

    It works only if the receiver is ui.pushButton_2 (and pos is 0, 0).
    But I want to send the click to the QMainWindow and decide by pos which widget will receive the click.

    How is it possible?

    Thank you very much!



  • Hey,

    Have a look at QTest
    Was useful for me, less complicated to simulate key press, mouse click



  • Thank you, but functions like mouseClick() had no effect.

    However, I was able to do what I wanted by sending to QWindow* instead (QApplication::allWindows().last()).


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.