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. How to change pushbutton color as well as keep the original mouse-hovered behaviour ?[Solved]

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

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 7.3k 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.
  • V Offline
    V Offline
    vivek.narvekar
    wrote on last edited by
    #1

    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
    0
    • ? This user is from outside of this forum
      ? This user is from outside of this forum
      Guest
      wrote on last edited by
      #2

      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
      0
      • V Offline
        V Offline
        vivek.narvekar
        wrote on last edited by
        #3

        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
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          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
          0
          • V Offline
            V Offline
            vivek.narvekar
            wrote on last edited by
            #5

            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
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              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
              0
              • V Offline
                V Offline
                vivek.narvekar
                wrote on last edited by
                #7

                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
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved