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 stylesheet hover
Qt 6.11 is out! See what's new in the release blog

qpushbutton stylesheet hover

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 7.7k Views 2 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.
  • R Offline
    R Offline
    rafael
    wrote on last edited by
    #1

    what code do i use to change the image whenever i hover over a qpushbutton?

    ui->closebutton->setStyleSheet("QPushButton:hover{image:url(:/images/OnOffArm.png);};");

    i tried the code above it doesn't change the image when i hover the button.

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Depending on how you want your image displayed you should use either QPushButton:hover{ border-image: url(:/images/OnOffArm.png) } or QPushButton:hover{ background-image: url(:/images/OnOffArm.png) }.
      If you mean the button icon then you can set it with QPushButton { qproperty-icon: url(:/images/OnOffArm.png) } but for some reason it doesn't work for the :hover state. I guess you can report a bug on that.

      M 1 Reply Last reply
      0
      • Chris KawaC Chris Kawa

        Depending on how you want your image displayed you should use either QPushButton:hover{ border-image: url(:/images/OnOffArm.png) } or QPushButton:hover{ background-image: url(:/images/OnOffArm.png) }.
        If you mean the button icon then you can set it with QPushButton { qproperty-icon: url(:/images/OnOffArm.png) } but for some reason it doesn't work for the :hover state. I guess you can report a bug on that.

        M Offline
        M Offline
        maximus
        wrote on last edited by maximus
        #3

        I can confirm that it's possible to do and hover is working on my side

        Here is a working example from my project:

                 ui->pushButton_config->setStyleSheet("QPushButton#pushButton_config{image: url(:/image/icon/conf2);border-radius: 1px;}"
                                                 "QPushButton#pushButton_config:hover{image: url(:/image/icon/conf2);border-radius: 1px;}");
        

        in Designer :

        <code>
        /* MINIMIZE */
        QPushButton#pushButton_minimize {
        image: url(:/image/icon/min1);
        border-radius: 1px;
        }

        QPushButton#pushButton_minimize:hover {
        image: url(:/image/icon/min2);
        border-radius: 1px;
        }
        </code>


        Free Indoor Cycling Software - https://maximumtrainer.com

        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