QKeyPress event in PyQt(PyQt 中的 QKeyPress 事件)
问题描述
我的软件有问题.在我的钢琴软件中,如果我一直按键盘上的一个键,那么它会为该特定键发出多个重复的相同音调.但实际上我需要一个单一的音调,直到释放那个特定的键.我提供了检测 keyPress 事件并调用相应方法的代码的一部分.那么我应该对我的代码进行哪些更改?
I am having issues with my software. In my piano software if I keep pressing a key on the keyboard then it is making multiple repeated same tones of that particular key. But actually I need a single tone until the release of that particular key. I'm providing a part of my code that detects the keyPress event and calls the corresponding method. So what should be the changes that I've to do with my code??
def keyPressEvent(self, event):
if type(event) == QtGui.QKeyEvent and event.key() == QtCore.Qt.Key_A :
self.Playnote('/home/hemanth/hemanth/Piano/C.mp3')
self.ui.pushButton.animateClick(100)
if type(event) == QtGui.QKeyEvent and event.key() == QtCore.Qt.Key_S:
self.Playnote('/home/hemanth/hemanth/Piano/D.mp3')
self.ui.pushButton_2.animateClick(100)
推荐答案
你应该检查 event.isAutoRepeat() 确定事件是由键盘自动重复还是实际按键引起的.如果是自动重复,请忽略该按.
You should check event.isAutoRepeat() to determine if the event is caused by keyboard autorepeat or an actual keypress. If it is an autorepeat, ignore that press.
这篇关于PyQt 中的 QKeyPress 事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PyQt 中的 QKeyPress 事件
基础教程推荐
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
