Results 1 to 5 of 5

Thread: Simulating a Button Click signal

  1. #1
    Join Date
    Nov 2009
    Posts
    60
    Thanks
    3
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Simulating a Button Click signal

    Hi All,

    I am trying to simulate a button click signal on an external event (presently I trying with Keyboard)

    I tried sending an mouse event on the focused widget by the code given below. This code is not able to call the corresponding slot initialized in the constructor.

    QMouseEvent mouseEvent(QEvent::MouseButtonPress,QCursor :: Pos(),Qt::LeftButton,Qt::LeftButton,Qt::NoModifier );
    QApplication::sendEvent(this->focusWidget(), &mouseEvent);

    And also I am not able to call mouse click simulation using QTest methods.
    QTest::mouseClick(this->focusWidget(),Qt::LeftButton,Qt::NoModifier,QCurs or ::Pos());



    Kindly give your valuable suggestion and help me in fixing this issue.

    Thanks in Advance.

    Ratheendran

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Simulating a Button Click signal

    Shouldn't you send event to qApp->focusWidget() ?

    Or you may also use QAbstractButton::click ()

  3. #3
    Join Date
    Nov 2009
    Posts
    60
    Thanks
    3
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Simulating a Button Click signal

    Thanks for your response.

    I relatively new to QT, I am not able to comprehend your reply.

    can you give me more details/ example of simple implementation.

    Ratheendran

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Simulating a Button Click signal

    QApplication::sendEvent(this->focusWidget(), &mouseEvent);
    should be
    QApplication::sendEvent(qApp->focusWidget(), &mouseEvent);

    and the place where you are calling this code from, you can instead use button->click(); where button is the pointer to the button you want to simulate the click for.

  5. #5
    Join Date
    Nov 2009
    Posts
    60
    Thanks
    3
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Simulating a Button Click signal

    Thanks again,

    I tried "QApplication::sendEvent(qApp->focusWidget(), &mouseEvent);" in my code this is not working.

    My application required signal to be send to the button on which cursor is active.

    so can you suggest any other alternative.

    Thanks,
    Ratheendran

Similar Threads

  1. Replies: 4
    Last Post: 27th November 2009, 13:00
  2. How can I know which button click.
    By electronicboy in forum Qt Programming
    Replies: 10
    Last Post: 4th October 2009, 14:27
  3. button click in webview
    By mind_freak in forum Qt Programming
    Replies: 1
    Last Post: 29th September 2009, 13:48
  4. QMdiSubWindow not delet when click the X button.
    By SamSong in forum Qt Programming
    Replies: 1
    Last Post: 20th May 2009, 08:21
  5. QPaintEvent on button click?
    By vishal.chauhan in forum Qt Programming
    Replies: 1
    Last Post: 5th June 2007, 08:44

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.