Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to change button style on touch event
Forum Updated to NodeBB v4.3 + New Features

How to change button style on touch event

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 444 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ariari
    wrote on 5 Jul 2024, 07:20 last edited by
    #1

    Hello,

    We have an application on Qt6 with an user interface. User can interact either with the mouse either by touch screen.

    When user clicks on a QPushButton we change its style (to show that the button has been clicked) using style sheet in the .ui. For example :
    QPushButton:pressed {
    icon:url(":/UI/Icons/photo-down.png");
    }

    This style sheet only applies on a mouse click. How to apply the same style sheet when user press touch screen ?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      ariari
      wrote on 16 Jul 2024, 08:51 last edited by
      #2

      Hello,
      Anyone can help us ?
      Do you need more information to understand our need ?

      J 1 Reply Last reply 16 Jul 2024, 09:25
      0
      • A ariari
        16 Jul 2024, 08:51

        Hello,
        Anyone can help us ?
        Do you need more information to understand our need ?

        J Offline
        J Offline
        JonB
        wrote on 16 Jul 2024, 09:25 last edited by JonB
        #3

        @ariari
        While you await a better answer, if anyone knows such.

        FWIW, https://stackoverflow.com/questions/28148805/qt-qpushbutton-style-sheet-properties-not-applied from 9 years ago asked the same question and received no solution. Since I do not see anywhere in the stylesheet docs support for any kind of "touched", only :pressed, I presume Qt stylesheet simply does not have support for the former. (I assume your :pressed does not work for a touch.) I offer the following as considerations:

        • If you subclass these push buttons (or use eventFilter() you could emit btn->pressed() (and correspondingly on release). I do not know whether there are nasty consequences for this, or even if it would work.

        • My other thought is, if there are no better solutions, you might use dynamic properties on the button with a corresponding CSS rule. That is documented in https://doc.qt.io/qt-6/stylesheet-syntax.html#selector-types, https://doc.qt.io/qt-6/stylesheet-examples.html#customizing-using-dynamic-properties, https://wiki.qt.io/Dynamic_Properties_and_Stylesheets. You would invent your own property, like touchPressed, which you would set and clear on touch actions. You should then be able to use that in your CSS styling rules. You may need to do some judicious unpolish()/polish() calls. I have used this in the past, though not for your case.

        1 Reply Last reply
        2

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved