我有QPushButton
我已连接到pressed()
信号,并设置autoRepeat=true
。
按钮在单击时(使用鼠标)更新一个数字,当您单击并按住它时重复。
使用鼠标可以正常工作。单击一次步骤,单击并按住重复它。简单的点击使用触摸屏工作正常,但它不会重复"点击并按住"。
我尝试禁用"点按并按住右键点击"在Windows 8中设置,但这没有帮助。它只会阻止右键单击。
如果我点击QPushButton并将手指从按钮移开(同时仍然按住),然后将手指移回QPushButton工作,则press()事件将开始autoRepeating。
MyPanel.ui:
<widget class="QPushButton" name="UpButton">
<property name="text">
<string/>
</property>
<property name="autoRepeat">
<bool>true</bool>
</property>
</widget>
<connection>
<sender>UpButton</sender>
<signal>pressed()</signal>
<receiver>my_panel</receiver>
<slot>UpAction()</slot>
<hints>
<hint type="sourcelabel">
<x>40</x>
<y>261</y>
</hint>
<hint type="destinationlabel">
<x>121</x>
<y>37</y>
</hint>
</hints>
</connection>
MyPanel.cpp:
void MyPanel::UpAction()
{
myNumber += 1;
}
答案 0 :(得分:0)
不要忘记查看官方文档 - Gestures Programming。在那里,您可以找到有关处理手势的有用信息。
通过在grabGesture(Qt::TapAndHoldGesture);
上设置QPushButton
,您忘记抓住您的手势了。启用此功能后,QPushButton
开始通过其TapAndHoldGesture
抓取event
。因此,您需要使用覆盖QPushButton
方法从event
继承您的按钮类。您现在可以控制手势识别和处理的整个过程。看看示例Image Gestures Example。