Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[Solved] Change color of push button



  • Hi Folks,

    I would like to create a pushBotton on my UI, but I need to change its color by specific user action. The first, I tried to change it on the UI designer: I clicked on the styleSheet property, but the setted color doesn't have any affect.
    Can anybody help me, how can I change the color?

    Regards,
    Norbert



  • I put the following in the styleSheet property of a push button and it worked for me.

    @background-color: rgb(255, 43, 39);@



  • Hi,

    this also works for me, but I only see this color when the button is pressed. After the release the button color set back to the default.

    Regards,
    Norbert



  • Can you post exactly what your stylesheet looks like?



  • Hi,

    if I open the styleSheet editor, I see the following line:
    @
    color: rgb(97, 255, 24);
    @

    This is some green color, but my buttons appers with the default grey color.

    Regards,
    Norbert

    Update:

    I found the following solution that works for me (little bit in pseudo code):
    @
    QPushButton instance->setStyleSheet("border: 1px; border-radius: 6px; background-color: " + QColor instance.name());
    @

    The "simple" change of the background-color didn't work, because the "border" property was not specified.

    Regards,
    Norbert


Log in to reply