Qt PushButton Hover/Pressed icons

12,988

Solution 1

You can set the style sheet for the QPushButton instance as shown below:

button->setStyleSheet("QPushButton {border-image: url(c:/Data/navArrowsSelected.png); } QPushButton:focus { border-image: url(c:/icons/button-hover.png }");

Solution 2

did you try the qproperty- syntax?

QToolButton {
    qproperty-icon: url(:/icon.png);
}
Share:
12,988
Connor M
Author by

Connor M

Updated on June 04, 2022

Comments

  • Connor M
    Connor M almost 2 years

    I'm beginning in Qt, and I want to set a QPushButton to a different icon whenever somebody hovers the mouse over it. Here's my code so far:

    #include <QPushButton>
    
    QPushButton *button = new QPushButton(mainWindow);
    button->setIcon(QIcon(":/icons/button.png"));
    button->setIconSize(QSize(128,56);
    button->setGeometry(0,0,128,56);
    

    I've heard something about stylesheets, but I have no clue how to use them and all the documentation is very confusing for me. Could somebody explain how I can set the icon to ":/icons/button-hover.png" whenever the mouse hovers on the button? Also, unless it's like exactly the same for when it's pressed, it would be great if you could show me that too.

    Thanks in advance :)