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. Change ToolButton image programatically
Forum Updated to NodeBB v4.3 + New Features

Change ToolButton image programatically

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.4k 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.
  • G Offline
    G Offline
    GregWilsonLindberg
    wrote on last edited by
    #1

    I'm building a system that will eventually run on a BeagleBone Black. Right now I'm doing my development on Kubuntu using QT4.6.5 & QTCreator 2.6.2.

    I'm trying to use toolbuttons as a radiobutton with an image. In my case the button state is set by the program and there is no user interaction to change the state, this happens from system state changes. What I would like to do is be able to set a parameter to change the displayed image. I'm specifying the image in a style sheet like this:
    @

    • {
      border: none;
      background-image: url(:/MainScreen/images/SnowOff.gif);
      }
      pressed {
      border: none;
      background-image: url(:/MainScreen/images/SnowOn_animated.gif);
      }
      @

    I starting by just specifying the images in the AbstractButton, but couldn't get the look that I wanted, so I changed to a style sheet.

    I've tried changing the down state and also the clicked state, but the only way that I've been able to actually change the image is by calling setIcon() which seems a bit heavy handed, and bypasses the style sheet.

    Am I missing something?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      GregWilsonLindberg
      wrote on last edited by
      #2

      I just realized that I can replace the image on a radio button and I've tried that but calling clicked() on the radio button still doesn't change the image.

      I'm obviously missing something.

      1 Reply Last reply
      0
      • McLionM Offline
        McLionM Offline
        McLion
        wrote on last edited by
        #3

        I encountered similar issues some time ago. Ended up with a new class (class AsButton : public QPushButton) which loaded the images and reimplemented the paint event.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          GregWilsonLindberg
          wrote on last edited by
          #4

          I think I've solved my problem, although I didn't answer my original question.

          I converted my state buttons to radio buttons, each with its own widget wrapper so that they are independent of each other. Then the setChecked() call properly sets the image that I want displayed. This is what I should have attempted first, had I figured out that the radio button allowed changing the graphic.

          It would be nice if the Check Box allowed changing the graphic, then I wouldn't have to have the extra widget wrappers around each of the state radio buttons.

          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