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. transition in QPushButton change from normal to hover and pressed:
Forum Updated to NodeBB v4.3 + New Features

transition in QPushButton change from normal to hover and pressed:

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 2.7k Views 1 Watching
  • 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.
  • N Offline
    N Offline
    nullbuil7
    wrote on last edited by nullbuil7
    #1

    hi I'm using Qt Creator and Stylesheet of my QPushButton looks like this:

    QPushButton {
    border: 1px solid rgb(24, 103, 155);
    border-radius: 5px;
    background-color: rgb(124, 203, 255);
    }
    QPushButton:hover {
    border: 1px solid rgb(24, 103, 155);
    border-radius: 5px;
    background-color: rgb(79, 176, 240);
     }
    QPushButton:pressed {
    border: 1px solid rgb(24, 103, 155);
    border-radius: 5px;
    background-color: rgb(20, 153, 240);
     }
    

    but now I want it to gradually change colors to hover or pressed like in half a second. how do i do that?

    Pl45m4P 1 Reply Last reply
    0
    • N nullbuil7

      hi I'm using Qt Creator and Stylesheet of my QPushButton looks like this:

      QPushButton {
      border: 1px solid rgb(24, 103, 155);
      border-radius: 5px;
      background-color: rgb(124, 203, 255);
      }
      QPushButton:hover {
      border: 1px solid rgb(24, 103, 155);
      border-radius: 5px;
      background-color: rgb(79, 176, 240);
       }
      QPushButton:pressed {
      border: 1px solid rgb(24, 103, 155);
      border-radius: 5px;
      background-color: rgb(20, 153, 240);
       }
      

      but now I want it to gradually change colors to hover or pressed like in half a second. how do i do that?

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #2

      @nullbuil7 said in transition in QPushButton change from normal to hover and pressed::

      in half a second

      Please explain.

      Stylesheets have no time based functions. If you want to change the stylesheet half a second later after you hovered your button, you will need to do that with some QTimer.

      transition in QPushButton change from normal to hover and pressed

      There is no real "transition". You could theoretically hover your cursor over one button for years without clicking it.
      Click and Hover are two independent actions. Ok, your cursor needs to be inside your button's rect in order to click, which is some "hovering"...

      So start the QTimer when your mouse enters your button and then adjust your stylesheet or start some QPropertyAnimation

      • https://doc.qt.io/qt-5/qpropertyanimation.html

      • https://doc.qt.io/qt-5/qwidget.html#enterEvent


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      2

      • Login

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