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. QToolButton: orange background?
QtWS25 Last Chance

QToolButton: orange background?

Scheduled Pinned Locked Moved General and Desktop
8 Posts 5 Posters 6.8k 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.
  • L Offline
    L Offline
    luafox
    wrote on last edited by
    #1

    I am using a number of QToolButtons. When you only provide one icon for the button, Qt automatically enhances the icon when the mouse is over (active) and also draws a sunken border around it, when pressed. This is fine, but for my purpose I need pressed icons to stand out more. So I would like to have a orange coloured background for "selected" buttons.

    I see two ways to get there:

    1. It is possible to define another selfmade icon for the different modes/states. And in principle I also managed to set my own icon for the selected mode. BUT: The automatic drawing of the sunken border is not switched off. So in selected mode the icon has now two borders, my own orange one and around that the automatic one provided by Qt. So is there a way to switch the automatic drawing/enhancement off if I provide my own icons for the different modes anyway?

    2. Would it be possible to set the background colour of the sunken border so that I do not need to provide my own icons? Can I set it using style sheets? If so it would be nice if you could point me in the right direction.

    Thank you very much!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sidewinder
      wrote on last edited by
      #2

      Style sheets are way to go. Check "Docs":http://qt-project.org/doc/qt-4.8/stylesheet.html, especially "Customizing Qt Widgets Using Style Sheets" and look for QToolButton in "Qt Style Sheets Reference".

      "Never memorize what you can look up in books."
      Albert Einstein

      1 Reply Last reply
      0
      • M Offline
        M Offline
        moritzg
        wrote on last edited by
        #3

        See the ColorRole section of the "QPalette":http://qt-project.org/doc/qt-4.8/qpalette.html documentation... customizing the different color roles may yield the desired effect. Alternatively, you can set QPalette::Button (or maybe QPalette::Window or QPalette::Base?) to transparent and then use your custom bevel icon.

        There are also ways of programatically creating such borders (see e.g. "QRubberBand":http://qt-project.org/doc/qt-4.8/qrubberband.html), but I think that may be more effort than is needed in this case.

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Peppy
          wrote on last edited by
          #4

          Yes, use stylesheets:
          @
          setStyleSheet(QString("QToolButton:selected { background-color: #FIND_ORANGE_COLOR; }"));
          @

          1 Reply Last reply
          0
          • L Offline
            L Offline
            luafox
            wrote on last edited by
            #5

            Thank you very much for the fast answers! I could not test it, yet but I think I will be able to do it now and read the documents carefully.

            1 Reply Last reply
            0
            • L Offline
              L Offline
              luafox
              wrote on last edited by
              #6

              Thanks again for your tipps. I got it working now. Still I have two followup questions:

              1. QToolButton:selected did not work in my example. I found out that one can use QToolButton:pressed for the appearance while the button is still pressed and QToolButton:checked if the button is checkable and stays in the pressed position.
                It took me quite a while and in the end I had to guess that ":checked" is the right way to go. Is there a documentation about which styles can be set and which possible values might be set? I found a few examples in the Qt Style Sheets Reference but it's far from beeing complete. I also found "border-style: inset" interesting but it is not easy for me to find out which other styles appart from "inset" are available. Is there a good place to look for it?

              2. When the button is pressed the content of the icon is moved in bottom right direction to support the feeling that the button is pressed. Can this be controlled anywhere?

              1 Reply Last reply
              0
              • R Offline
                R Offline
                raaghuu
                wrote on last edited by
                #7

                "this":http://qt-project.org/doc/qt-4.8/stylesheet-reference.html and "this":http://qt-project.org/doc/qt-4.8/stylesheet.html contain a lot of info on style-sheets

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  luafox
                  wrote on last edited by
                  #8

                  Ok, thanks, I found the information I was looking for in the pseudo-states section of the style sheet reference - I did not know this site before.

                  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