A good way to set style for a clicked QPushButton (indicates as active)

  • Hi!

    I'm looking for a good solution to set the button's style after clicked (stay after clicked) via QSS. The current solution is setting a new class name via a dynamic property and update the container-widget and the button (via setstyle).

    Here's the code so far:

    @if (m_ActiveNavigationButton != NULL)
    m_ActiveNavigationButton->setProperty("isActiveButton", false);
    m_ActiveNavigationButton = navibutton;
    m_ActiveNavigationButton->setProperty("isActiveButton", true);
    m_ActiveNavigationButton = navibutton;
    navibutton->setProperty("isActiveButton", true);

    Is there a solution in QSS or is it necessary to update the window in that way? I know that i can use the "pressed-state" in QSS, but it only appears at click and does not stay after click.

    Any ideas on that?

    Thank you !!

  • Lifetime Qt Champion


    IIRC you also have to set the style for the checked state

    Hope it helps

  • You mean QPushButton::Checked?

  • Lifetime Qt Champion



  • In addition to above, you also need to set 'setCheckable(true)' property for your PushButton.

  • Thank you for your answers.

    I will try it today and give some feedback. Excuse the late answer...i was sick and now i'm back to business.

    Have a nice day!

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.