問題描述
我的軟件有問題.在我的鋼琴軟件中,如果我一直按鍵盤上的一個(gè)鍵,那么它會(huì)為該特定鍵發(fā)出多個(gè)重復(fù)的相同音調(diào).但實(shí)際上我需要一個(gè)單一的音調(diào),直到釋放那個(gè)特定的鍵.我提供了檢測(cè) keyPress 事件并調(diào)用相應(yīng)方法的代碼的一部分.那么我應(yīng)該對(duì)我的代碼進(jìn)行哪些更改?
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)
推薦答案
你應(yīng)該檢查 event.isAutoRepeat()
確定事件是由鍵盤自動(dòng)重復(fù)還是實(shí)際按鍵引起的.如果是自動(dòng)重復(fù),請(qǐng)忽略該按.
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.
這篇關(guān)于PyQt 中的 QKeyPress 事件的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!