問題描述
我有一個 QAbstractItemView
需要對單擊和雙擊事件做出反應.根據是單擊還是雙擊,操作會有所不同.出現的問題是在雙擊事件之前接收到單擊事件.
I have a QAbstractItemView
that needs to react to single and double click events. The actions are different depending on whether it was single clicked or double clicked. The problem that is occurring is that the single click event is received prior to the double click event.
是否有推薦的方法/最佳實踐來區分兩者?當用戶實際雙擊時,我不想執行單擊操作.
Is there a recommended way/best practice for distinguishing between the two? I don't want to perform the single click action when the user has actually double clicked.
我使用的是 Qt 4.6
I am using Qt 4.6
推薦答案
您可以在標題為 在 QtCentre 論壇上的雙擊捕獲;
You can find answer in the thread titled Double Click Capturing on QtCentre forum;
你可以有一個計時器.啟動releaseEvent 處理程序中的計時器和確保超時時間足夠長首先處理雙擊.然后,在雙擊事件中處理程序,您可以停止計時器和防止它開火.如果雙單擊處理程序未觸發,計時器將超時并調用一個插槽您的選擇,您可以在哪里處理單擊.這當然是一個討厭的黑客,但有機會工作.
You could have a timer. Start the timer in the releaseEvent handler and make sure the timeout is long enough to handle the double click first. Then, in the double click event handler you can stop the timer and prevent it from firing. If a double click handler is not triggered, the timer will timeout and call a slot of your choice, where you can handle the single click. This is of course a nasty hack, but has a chance to work.
威索塔
這篇關于Qt中單擊和雙擊事件的區別的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!