Results 1 to 4 of 4

Thread: Pushbutton widget auto Repeat on touchscreen pressed

  1. #1
    Join Date
    Dec 2017
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Pushbutton widget auto Repeat on touchscreen pressed

    Hi,
    I have a pushbutton widget on a window and Auto repeat is enabled for that pushbutton.
    Qt Code:
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <ui version="4.0">
    3. <class>ManualModes</class>
    4. <widget class="QMainWindow" name="ManualModes">
    5. <property name="geometry">
    6. <rect>
    7. <x>0</x>
    8. <y>0</y>
    9. <width>272</width>
    10. <height>287</height>
    11. </rect>
    12. </property>
    13. <property name="sizePolicy">
    14. <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
    15. <horstretch>0</horstretch>
    16. <verstretch>0</verstretch>
    17. </sizepolicy>
    18. </property>
    19. <property name="windowTitle">
    20. <string>MainWindow</string>
    21. </property>
    22. <property name="styleSheet">
    23. <string notr="true">background-color: rgb(40, 40, 40);</string>
    24. </property>
    25. <widget class="QWidget" name="centralwidget">
    26. <widget class="QPushButton" name="M_Spot_Up">
    27. <property name="geometry">
    28. <rect>
    29. <x>210</x>
    30. <y>2</y>
    31. <width>55</width>
    32. <height>40</height>
    33. </rect>
    34. </property>
    35. <property name="sizePolicy">
    36. <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
    37. <horstretch>0</horstretch>
    38. <verstretch>0</verstretch>
    39. </sizepolicy>
    40. </property>
    41. <property name="focusPolicy">
    42. <enum>Qt::NoFocus</enum>
    43. </property>
    44. <property name="styleSheet">
    45. <string notr="true">border-image: url(:/resources/resources/other/button_arrow_up_off1.png);</string>
    46. </property>
    47. <property name="text">
    48. <string/>
    49. </property>
    50. <property name="iconSize">
    51. <size>
    52. <width>55</width>
    53. <height>40</height>
    54. </size>
    55. </property>
    56. <property name="autoRepeat">
    57. <bool>true</bool>
    58. </property>
    59. <property name="autoRepeatDelay">
    60. <number>10</number>
    61. </property>
    62. <property name="autoRepeatInterval">
    63. <number>50</number>
    64. </property>
    65. </widget>
    66. </widget>
    67. </widget>
    68. <resources/>
    69. <connections/>
    70. </ui>
    To copy to clipboard, switch view to plain text mode 

    Now I have Slots for pressed and released as follows:
    Qt Code:
    1. void ManualModes::on_M_Spot_Up_pressed()
    2. {
    3. bool res = false;
    4. if(Status.ReadyForMB)
    5. {
    6. qDebug()<<"Spot Up Pressed";
    7. if(this->inAction != true)
    8. {
    9. ui->M_Spot_Up->setStyleSheet(QString::fromUtf8 ("QPushButton {border-image: url(:/resources/resources/other/button_arrow_up_on1.png);}"));
    10. this->inAction = true;
    11. }
    12. res = sendDataPacket(P_BackSpotUp,true);
    13. if(!res)
    14. {
    15. qDebug() << "P_BackSpotUp Packet sent fail";
    16. }
    17. }
    18. }
    19. void ManualModes::on_M_Spot_Up_released()
    20. {
    21. if(Status.ReadyForMB)
    22. {
    23. qDebug()<<"Spot Up Released";
    24. this->inAction = false;
    25. ui->M_Spot_Up->setStyleSheet(QString::fromUtf8 ("QPushButton {border-image: url(:/resources/resources/other/button_arrow_up_off1.png);}"));
    26. }
    27. }
    To copy to clipboard, switch view to plain text mode 

    My Intention,Over here Is When I press the button and hold(touchscreen), It should be invoking on_M_Spot_Up_pressed continuously with auto repeat interval. And when I release the button It should invoke on_M_Spot_Up_released.
    But In my code, When I press and Hold I am seeing both pressed and released called continuously instead of only pressed.

    Debug Output:

    Spot Up Pressed
    Spot Up Released
    Spot Up Pressed
    Spot Up Released
    Spot Up Pressed
    Spot Up Released
    Spot Up Pressed
    Spot Up Released
    Spot Up Pressed
    Spot Up Released
    Spot Up Pressed
    Spot Up Released
    Any Help how to resolve this problem on this push button widget.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Pushbutton widget auto Repeat on touchscreen pressed

    My guess is that this is how autorepeat is implemented by the driver for your touchscreen - as a sequence of pressed() / released() signals. If you install an event filter on the button and monitor QEvent::MousePress and QEvent::MouseRelease you can see if the touchscreen is actually sending a sequence of these or is emitting the pressed() and released() signals that you are handling.

    But except for your code that changes the icon on the pushbutton, having this sequence of signals doesn't change what you want to do with each button press - send a data packet.

    I am guessing that your button is also sending a series of clicked() signals that you aren't handling.

    A workaround for your problem could be to use a QTimer to change the icon to the inactive state rather than relying on the released() signal: Add a QTimer as a member of your ManualModes class. When the pushbutton pressed() slot is called, change the icon and then start the QTimer with a timeout a bit more than the autorepeat delay. Implement a slot for the QTimer's timeout() signal. In that slot, change the icon back to inactive.

    As long as the autorepeat is active, the QTimer will be reset with each pressed() signal and won't fire because its timeout delay is longer than the autorepeat delay. When you release the button, the timer will timeout shortly afterward and the icon will be reset.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Dec 2017
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Pushbutton widget auto Repeat on touchscreen pressed

    Hi @d_stranz,
    Thanks for your reply. Seems the QTimer workaround might work for us to change the image to inactive. But what we see is some times onpress also, we are seeing pressevent(on_M_Spot_Up_pressed) not being invoked. In those cases, if we swipe little bit then the press event is invoked. So to be more precise, This scenario looks similar to problem mentioned in the post: https://stackoverflow.com/questions/...shbutton-in-qt
    But in our case it's embedded application with only touch input. So will TapAndHoldGesture be helpful to us? If so can you please point us to some examples on how to do this?

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Pushbutton widget auto Repeat on touchscreen pressed

    So will TapAndHoldGesture be helpful to us?
    I can't really help you there. I haven't done any programming for touchscreen gesture applications - everything I have done so far is for desktop / laptop use with the keyboard and mouse. If I ever start in on that, I am sure I will run into the same walls as you have.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Qt5 auto repeat
    By chocoleet in forum Qt Programming
    Replies: 1
    Last Post: 29th December 2015, 09:33
  2. How to change QLabel value after Pushbutton pressed?
    By rdelgado in forum Qt Programming
    Replies: 4
    Last Post: 16th August 2010, 21:25
  3. keyPressEvent - auto-repeat immediately
    By Macok in forum Qt Programming
    Replies: 1
    Last Post: 16th March 2009, 05:31
  4. Keyboard auto repeat
    By akiross in forum Qt Programming
    Replies: 7
    Last Post: 4th March 2007, 16:05
  5. How to disable auto-repeat?
    By lumber44 in forum Qt Programming
    Replies: 1
    Last Post: 24th February 2006, 09:20

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.