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. A good way to set style for a clicked QPushButton (indicates as active)
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 4.5k Views
  • 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.
  • jensen82J Offline
    jensen82J Offline
    jensen82
    wrote on last edited by
    #1

    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->setStyle(QApplication::style());
    m_ActiveNavigationButton = navibutton;
    m_ActiveNavigationButton->setProperty("isActiveButton", true);
    m_ActiveNavigationButton->setStyle(QApplication::style());
    }
    else
    {
    m_ActiveNavigationButton = navibutton;
    navibutton->setProperty("isActiveButton", true);
    m_ActiveNavigationButton->setStyle(QApplication::style());
    }
    update();
    repaint();@

    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 !!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • jensen82J Offline
        jensen82J Offline
        jensen82
        wrote on last edited by
        #3

        You mean QPushButton::Checked?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Rather:

          @"QToolButton:enabled:checked"@

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • B Offline
            B Offline
            blueshift
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • jensen82J Offline
              jensen82J Offline
              jensen82
              wrote on last edited by
              #6

              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!

              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