Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulating a mouse click event in PyQt

Tags:

qt

pyqt

I am trying to simulate a mouse click event in Python on the ui.goButton widget.

Here is what I did:

QtTest.QTest.mouseClick(self.ui.goButton, QtCore.Qt.LeftButton)

Is this the right way to do it? Cause it is not working.

like image 653
Vilfrin Avatar asked Aug 11 '10 11:08

Vilfrin


1 Answers

Based on your reply to the comment, I will answer your question.

Basically signals can be emitted by,

emit signalToBeEmitted()

So, if you want to emit the QPushButton's clicked() signal,

you have to inherit the QPushButton and you can emit the signal like emit clicked().

This example will help you in emitting the signals.

But my question is why you want to do that?

By emitting the clicked() signal, you will in turn call the connected slot.. So why can't you call the slot directly by yourself instead of emitting the signal and then calling the slot..

Remember slots are just ordinary functions which can be called just like other functions.

Or else, if the slot present in another object which you will connect through the signal, then emit your own signal instead of messing up with the pre-defined ones.

IMHO, Don't emit such pre-defined signals even for the shorter term..

Hope it helps..

Edit:

Oops I didn't see the PyQt. I am used to Qt with C++. I know nothing about Python. But I believe most of the concepts of Qt will remain common. So I will leave my answer as such..

like image 200
liaK Avatar answered Sep 26 '22 06:09

liaK