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. QPushButton image with states.
Qt 6.11 is out! See what's new in the release blog

QPushButton image with states.

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 3.9k Views 1 Watching
  • 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hello there, I was wandering if is it possible to have a pressed state in QPushButton. I have a QPushButton with a png as drawable and, when I click on it I want to change its background for 500ms and then restore it. Any idea?

    EDIT:

    I found it:

    @ QPushButton#evilButton:pressed {
    background-color: rgb(224, 0, 0);
    border-style: inset;
    }@

    can this be done programmatically?

    I tried with this stylesheet:
    EDIT2:
    @
    QPushButton { background: transparent; border: none;} QPushButton:pressed { background-image: url(\mypath\settings_press.png); }
    @
    but i get this error:

    Could not parse stylesheet of widget

    Anyone?

    EDIT 3: the issue is related to the slashes direction:
    Changing in this way works, but still i can not see any image.
    @
    QPushButton { background-image: url(/mypath/settings.png);} QPushButton:pressed { background-image: url(/mypath/settings_press.png); }
    @

    Any idea?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jys0224
      wrote on last edited by
      #2

      i think you can subclass QPushButton and reimplement paint function.
      state can be acquire from isChecked(), isDown(),..

      and,,, QTimer can be used for background to be restored after a while.

      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