繁体   English   中英

在QT的QPushButton上捕获“点击并按住”触摸事件的问题

[英]Problems catching “Tap and hold” touch event on QPushButton in QT

我有一个QPushButton ,我已在其中连接了pressed()信号,并设置了autoRepeat=true

单击(使用鼠标)时,按钮将更新一个数字,单击并按住该按钮将重复该数字。

使用鼠标可以正常工作。 单击一次,单击并按住重复一次。 使用触摸屏,只需轻按一下即可正常工作,但在“轻按并按住”时不会重复。

我尝试禁用Windows 8中的“点击并按住右键”设置,但这没有帮助。 它仅防止发生右键单击。

如果我点击QPushButton并将手指从按钮上移开(同时保持住),然后将手指移回到QPushButton的工作方式,那么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;
}

不要忘记看一下官方文档- 手势编程 在那里您可以找到有关处理手势的有用信息。

你忘了抓住你的姿态,通过设置grabGesture(Qt::TapAndHoldGesture); 在您的QPushButton 启用此选项后,您的QPushButton开始通过其event捕获TapAndHoldGesture 因此,您需要使用重写的event方法从QPushButton继承按钮类。 您现在可以控制手势识别和处理的整个过程。 看一下示例“ 图像手势”示例

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM