c++ - 在 QT 中的 QPushButton 上捕获 "Tap and hold"触摸事件时出现问题

标签 c++ qt windows-8 touch multi-touch

我有一个 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/

相关文章:

c++ - Qt在菜单项单击时显示模式对话框(.ui)

QT如何给按钮添加 Action

c++ - 编码(marshal) C++ 锯齿状数组给出 "Invalid managed/unmanaged type combination"错误

c++ - 为什么QWidget升级后就消失了?

使用类型特征调用 C++ 条件函数

c# - 将现有数据库(存储文件)复制到存储文件夹

windows - 让 windows 8 显示 "How do you want to open"对话框?

c# - 当应用程序在 Windows 8 XAML/C# 应用程序中有超过 1 个页面时出现 SuspensionManager 错误

c++ - 从 C++ std::vector<float> 转换为 Rust Vec<f32> 的最佳方法是什么?

c++ - 通过多个定界符解析 C++ 中的字符串