Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    QToolButton setStyleSheet sets stylesheet on tooltip

    General and Desktop
    3
    4
    13455
    Loading More Posts
    • 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.
    • S
      Soerenc last edited by

      Hello

      I have a problem with a QToolButton. It is placed on a dark background, so the button textcolor is set to white with the stylesheet
      @helpButton->setStyleSheet("color: white;");@

      And it works great. The problem is, that the button also has a tooltip, but now the textcolor of the tooltip is also set to white, but the tooltip background is almost white, so the text is not visible.

      My question is, how do I set a stylesheet on my button that sets the textcolor to white, but keeps the original tooltip textcolor?

      I have tried
      @helpButton->setStyleSheet("QToolButton{ color: white;}");@
      and
      @helpButton->setStyleSheet("color: white; QToolTip{ color: black;}");@
      And other variations, but without the desired effect.

      1 Reply Last reply Reply Quote 0
      • A
        andre last edited by

        You could try to use the decendant selector:
        @
        QToolButton { color: white;}
        QToolButton QWidget { color: black;}
        @

        I am using QWidget, because I don't know of what class the actual popup is. It is not QToolTip; the actual class seems to be private.

        1 Reply Last reply Reply Quote 0
        • G
          giesbert last edited by

          so, the first solution sets the color for everything to white. And style sheets are used in child widgets as well, so for the first version, the result is clear.

          But the second one should work.

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply Reply Quote 0
          • S
            Soerenc last edited by

            I tried
            @helpButton->setStyleSheet("QToolButton { color: white;} QToolButton QWidget { color: black;}");@
            and it works perfectly. Thank you for a fast and great solution :)

            1 Reply Last reply Reply Quote 0
            • First post
              Last post