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. [SOLVED] Simulate input for a QMainWindow
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Simulate input for a QMainWindow

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.4k 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.
  • Q Offline
    Q Offline
    qtacc32
    wrote on last edited by qtacc32
    #1

    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!

    1 Reply Last reply
    0
    • M Offline
      M Offline
      maximus
      wrote on last edited by
      #2

      Hey,

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


      Free Indoor Cycling Software - https://maximumtrainer.com

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qtacc32
        wrote on last edited by
        #3

        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()).

        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