2014-10-17 445 views
0

我有一个QPushButton,其中我已连接到pressed()信号,并设置了autoRepeat=trueQT中的QPushButton上的“点按并按住”触摸事件的问题

该按钮用鼠标单击时更新一个数字,并且当您单击并按住它时重复该按钮。

这适用于鼠标。单击一次,单击并保持重复。简单的水龙头可以使用触摸屏正常工作,但不会在“点按并按住”时重复。

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

如果我点击QPushButton并将手指从按钮上移开(同时仍然按住),然后将手指移回QPushButton工作区,pressed()事件将启动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; 
} 
+1

您是否尝试过使用'Qt :: TapAndHoldGesture'? – nnb 2014-10-17 12:20:50

回答

0

不要忘了看看官方文档 - Gestures Programming。在那里你可以找到关于处理手势的有用信息。

您忘记了抓取您的手势,通过在QPushButton上设置grabGesture(Qt::TapAndHoldGesture);。当您启用此功能时,您的QPushButton开始通过event获取TapAndHoldGesture s。所以你需要让你的按钮类从QPushButton继承,并使用event方法。您现在可以控制整个手势识别和处理过程。看看例子Image Gestures Example