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 support :pressed state of style sheet for custom widget ?

How to support :pressed state of style sheet for custom widget ?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.5k 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
    andamedanda
    wrote on last edited by
    #1

    What i have :-
    I have a custom widget which extends QFrame (instead of QWidget as QFrame already has a working paintEvent implementation). I have overridden the mousePressed() and mouseReleased() to emit the pressed() released() and clicked() Signals. Everything upto this point is woring fine as expected.

    What i need :-
    This custom widget is having basic style sheet support and it supports the :hover state just fine.
    But the :pressed state is not working. I have already figured out that this is bcoz its not supported by QFrame/QLabel etc.
    I wish to know what do i need to do in order to support the :pressed state.
    Should i set some attribute / property on pressed and released OR anything else ?

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      AFAIK this it's not possible to use pseudo states (and sub-controls) with custom widgets (except the one which are supported by the base class).

      But you can set a custom dynamic property and check for it in the stylesheet:
      @
      void MyWidget::mousePressEvent(...)
      {
      this->setProperty("pressed", true);
      this->style()->polish(this);
      }
      void MyWidget::mouseReleaseEvent(...)
      {
      this->setProperty("pressed", false);
      this->style()->polish(this);
      }
      @

      in the stylesheet:
      @
      MyWidget[pressed="true"]
      {
      ...
      }
      @

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andamedanda
        wrote on last edited by
        #3

        Thanks raven,
        I was expecting a standard property or attribute which pertains to the state. But i guess there is not, This does the job :)

        1 Reply Last reply
        0

        • Login

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