我有一个 QPushButton
,我已在其中连接到 pressed()
信号,并设置了 autoRepeat=true
。
单击(使用鼠标)按钮会更新一个数字,当您单击并按住它时,它会重复。
这适用于鼠标。单击一次步骤,单击并按住重复它。简单的点击在触摸屏上工作正常,但它不会在“点击并按住”时重复。
我曾尝试禁用 Windows 8 中的“点击并按住以右键单击”设置,但这没有帮助。它只会阻止右键单击的发生。
如果我点击 QPushButton 并将手指从按钮上移开(同时保持按住),然后将手指移回 QPushButton works,pressed() 事件将开始自动重复。
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;
}
最佳答案
不要忘记查看官方文档 -- Gestures Programming .您可以在那里找到有关处理手势的有用信息。
您忘记了抓取您的手势,方法是在您的QPushButton
上设置grabGesture(Qt::TapAndHoldGesture);
。当您启用它时,您的QPushButton
开始通过其事件
获取TapAndHoldGesture
。因此,您需要使用覆盖的 event
方法从 QPushButton
继承您的按钮类。您现在可以控制手势识别和处理的整个过程。看例子Image Gestures Example .
关于c++ - 在 QT 中的 QPushButton 上捕获 "Tap and hold"触摸事件时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26424333/