Please nominate your Qt Champions for 2021!

Change QPushButton opacity on hover and pressed states.

  • Well the title it's self explanatory. I am trying to achieve those results for buttons that are not created with the designer. They are generated via code.
    That behavior is most likely achievable true QSS - therefor how to set the style sheet most efficiently.
    What I am thinking of is setStyleSheet(blablalba) in the constructor - is there any way better than that?
    Can someone better than me with QSS (obviously) help me with the syntax ?

  • as you suggested using setStyleSheet(blablalba) in the constructor is totally fine

  • @gde23 Any help with the states syntax ?

  • e.g.

        background: rgba(255, 0, 125, 125);
        background: rgba(0, 0, 0, 125);

    or in general take a look at the examples:

  • @gde23 Thank you!
    Your comment led me to results. Thank you !

    	background-color: rgba(0, 172, 252, 30);
    	border:0px solid rgb(0,175,252);
    	border-style: outset;
    	border-width: 1px;
    	margin-bottom: 1px;
    	background-color: rgba(0, 172, 252, 50);
    	background-color: rgba(0, 120, 252, 150);
        border-style: inset;
        border-width: 2px;

    During the process I've learned that you can also set border-image for each state of the button. So any rater complex design can be achieved true Photoshop as QSS supports .png with alpha.

    One more thing I am concerned right now and it's if I am able to support custom button shapes let's say I'll want my button to appear as an image of a house, but only be able to click inside the image area.
    Like here - Image

Log in to reply