Qt Forum

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

    Update: Forum Guidelines & Code of Conduct

    How to change pushbutton color as well as keep the original mouse-hovered behaviour ?[Solved]

    General and Desktop
    2
    7
    6777
    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.
    • V
      vivek.narvekar last edited by

      I am using Qt 4.8.0
      When we create a pushbutton, it assumes a default gradient grey color. Also, on mouse-hover, it shows a gradient blue color.
      I want to keep similar behaviour, but only change the colors.

      For example, I want a pushbutton to normally appear in gradient blue color, and on mouse-hover, the color should change to gradient yellow color.

      I tried using qpalette for this, but was unsuccessful. Using stylesheet I was partially successful, but could not set mouse-hovered color

      Any help is greatly appreciated.

      Thank You
      vivek

      1 Reply Last reply Reply Quote 0
      • ?
        Guest last edited by

        Hello,

        this style sheet code should help, if I understood correctly what you want to do. It has a QLinearGradient in blue, with red on hover.
        It's a little modified example from Documentation.
        Cheers

        @
        QPushButton {
        background: qlineargradient(x1:0, y1:1, x2:1, y2:1,
        stop:0 white, stop: 0.4 blue, stop:1 white)
        }

        QPushButton:hover{
        background: qlineargradient(x1:0, y1:1, x2:1, y2:1,
        stop:0 white, stop: 0.4 red, stop:1 white)
        }
        @

        [quote author="vivek.narvekar" date="1331816005"]I am using Qt 4.8.0
        When we create a pushbutton, it assumes a default gradient grey color. Also, on mouse-hover, it shows a gradient blue color.
        I want to keep similar behaviour, but only change the colors.

        For example, I want a pushbutton to normally appear in gradient blue color, and on mouse-hover, the color should change to gradient yellow color.

        I tried using qpalette for this, but was unsuccessful. Using stylesheet I was partially successful, but could not set mouse-hovered color

        Any help is greatly appreciated.

        Thank You
        vivek

        [/quote]

        1 Reply Last reply Reply Quote 0
        • V
          vivek.narvekar last edited by

          Hello g.lex,

          Thanks a lot for the useful information.

          It does work.

          But the only thing is that the transition in the color (when the mouse is hovered) is not as smooth as that happens for the default color settings. ie the color changes abruptly from blue gradient to red gradient when the mouse is hovered. Any settings for this ?

          Thanks a lot for help
          Regards
          Vivek

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

            No, there are no settings for that. You'd have to create an animation like that yourself, manually, and subclass your button to manually handle the redraws.

            1 Reply Last reply Reply Quote 0
            • V
              vivek.narvekar last edited by

              Thanks Andre for the information.

              In that case, I think I should better keep default behaviour, since I was planning to do this for all the widgets, starting with push button

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

                For these kinds of customizations, that include animations, the Qt Widgets system is not all that suitable. A lot is possible, but it is not easy to do. If you want a customized UI like that contains animations, you should considder QML, perhaps in conjunction with the Desktop Components.

                1 Reply Last reply Reply Quote 0
                • V
                  vivek.narvekar last edited by

                  Actually we are migrating from a very old version of Qt (3.0.4) to Qt(4.8.0). So, along the course, i am trying to use new features provided by Qt, which can be quickly implemented without major change in existing code structure.

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