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. [SOLVED] QToolButton, QPushButton, style sheets and disabling

[SOLVED] QToolButton, QPushButton, style sheets and disabling

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 13.1k 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.
  • A Offline
    A Offline
    Anticross
    wrote on last edited by
    #1

    I've got a ui with dialog window and some checkable buttons. For buttons I used a QToolButton class and made them icon with text beside icon. So I need to disable clicks on some of them, but if I use a set them disabled the icon will be gray-scale bitmap. I have some ideas like to use style sheet "border-style: outset; border-width: 2px; border-color: red; " and border-style: outset; border-width: 2px; border-color: blue; " to visualize difference between disabled and enabled buttons. The next step to disable clicking on red buttons. I think about get button click() signal and do reverse click or to get mouse click event and do the click if cursor on blue button and not on red(in this way I need to some list which stores my red button object names). So the question is obvious: "Is there any other simple way to solve this problem ?"

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      You can make the visual distinction between your enabled and disabled buttons using the stylesheet. However, instead of changing the behaviour of the widget based on the colors you set, you should do the reverse: craft your stylesheet so it uses the right styles for the enabled and for the disabled states. The Qt stylesheet system gives you a load of different pseudo states to do that, among them the :disabled and the :enabled pseudo-states. You can use these in your selectors for the style.

      Then, you can just enable or disable the button, and the visual appearance will follow suit. Note that if you don't like the grey image on disabled buttons, you can set your own image by setting an appropriate image for the disabled mode in the QIcon you set for the button.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giesbert
        wrote on last edited by
        #3

        soemwhere, you set the QIcon. You can set different *.png files for different states on a "QIcon":http://doc.qt.nokia.com/latest/qicon.html .

        like this:
        @
        QIcon ico;
        ico.addPixmap(QPixmap(":/on.png"), QIcon::Normal);
        ico.addPixmap(QPixmap(":/on.png"), QIcon::Disabled);
        @

        Nokia Certified Qt Specialist.
        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

        1 Reply Last reply
        1
        • A Offline
          A Offline
          Anticross
          wrote on last edited by
          #4

          Thanks a lot Gerolf it is the simplest way. I forgot that I'm using ui file :)

          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