在 PyQt 中模拟鼠标点击事件
我正在尝试在 ui.goButton
小部件上用 Python 模拟鼠标单击事件。
这就是我所做的:
QtTest.QTest.mouseClick(self.ui.goButton, QtCore.Qt.LeftButton)
这是正确的方法吗?因为它不起作用。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您对评论的回复,我将回答您的问题。
基本上信号可以通过以下方式发出,
因此,如果您想发出
QPushButton
的clicked()
信号,您必须继承< code>QPushButton 并且您可以发出信号,例如
emit clicked()
。此示例将帮助您发出信号。
但我的问题是你为什么要这样做?
通过发出
clicked()
信号,你将依次调用connect
ed 插槽。那么为什么你不能自己直接调用槽而不是发出信号然后调用槽。记住
槽
只是普通函数否则,如果插槽存在于您将通过信号连接的另一个对象中,则发出您自己的信号,而不是弄乱预定义的信号。
恕我直言,即使在短期内也不要发出这样的预定义信号..
希望它有帮助..
编辑:
哎呀我没有看到 PyQt。我习惯了 Qt 和 C++。我对Python一无所知。但我相信 Qt 的大部分概念仍将是通用的。所以我会留下我的答案..
Based on your reply to the comment, I will answer your question.
Basically signals can be emitted by,
So, if you want to emit the
QPushButton
'sclicked()
signal,you have to inherit the
QPushButton
and you can emit the signal likeemit 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 theconnect
ed 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..