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. Stylesheet for making a button flat?

Stylesheet for making a button flat?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 8.4k 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
    Violet Giraffe
    wrote on 22 Jun 2014, 07:28 last edited by
    #1

    I need a button that looks exactly like a QToolButton with autoRaise=true. However, QToolButton has a problem: after being highlighted when hovered, it often wouldn't lose highlight as mouse cursor moves off (tested and confirmed on Windows 7 and Linux with KDE).

    So, I'm wondering if it's possible to make a regular button (either QPushButton or QToolButton) flat by means of a QSS stylesheet.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 22 Jun 2014, 10:35 last edited by
      #2

      [quote author="Violet Giraffe" date="1403422120"]QToolButton has a problem: after being highlighted when hovered, it often wouldn't lose highlight as mouse cursor moves off (tested and confirmed on Windows 7 and Linux with KDE).[/quote]
      Is that a known bug? I can't seem to reproduce it. Which compiler and Qt version are you using?

      [quote author="Violet Giraffe" date="1403422120"]So, I'm wondering if it's possible to make a regular button (either QPushButton or QToolButton) flat by means of a QSS stylesheet.[/quote]
      Not entirely, no.
      You can make the button borderless and transparent and give it some highlight on hover:
      @
      QPushButton {
      border: none;
      background: transparent;
      }

      QPushButton:hover {
      border: 1px solid blue;
      background: red;
      }
      @
      but the colors will be fixed and no system style(gradients, animation etc) will be applied. You can use "palette(button)" etc. as colors to make it closer to system look but it won't look 100% native.

      1 Reply Last reply
      0
      • V Offline
        V Offline
        Violet Giraffe
        wrote on 22 Jun 2014, 11:33 last edited by
        #3

        [quote author="Chris Kawa" date="1403433300"]
        Is that a known bug?[/quote]
        No idea. Visual Studio 2012 and gcc 4.8.2 (not that it could be caused by a compiler), Qt 5.3 final on both systems.

        The bug is more complicated than I've initially described. It happens when button click opens QMenu. Then, if you click anywhere on the window to close the menu, the button will become highlighted until you hover it.

        1 Reply Last reply
        0

        2/3

        22 Jun 2014, 10:35

        • Login

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