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
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 包装空间模型 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01