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. A problem when setting QIcon and stylesheet of QPushButton
Forum Updated to NodeBB v4.3 + New Features

A problem when setting QIcon and stylesheet of QPushButton

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.9k 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.
  • S Offline
    S Offline
    sczhengyabin
    wrote on last edited by
    #1

    Hi,
    I got a problem when I tried to set 3 different looks for 3states of QPushButton : normal, pressed, disabled.

      I Only have 2 pictures for Normal & Pressed state. And I want the look of the disabled state to be like the Qt self does to a disabled QIcon, that is to grey the button.
    
      I've tried a lot of methods, they didn't work. Anybody knows how to do this stuff?
    
     Thanks.
    
    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on last edited by
      #2

      Here is an example that I've got from designer.
      It creates a new QPushButton and sets different colours for active, inactive and disabled state.
      @
      pushButton = new QPushButton(widgetPlayback);
      pushButton->setObjectName(QStringLiteral("pushButton"));
      pushButton->setGeometry(QRect(110, 210, 80, 23));
      QPalette palette;
      QBrush brush(QColor(54, 239, 156, 255));
      brush.setStyle(Qt::SolidPattern);
      palette.setBrush(QPalette::Active, QPalette::Button, brush);
      QBrush brush1(QColor(199, 239, 111, 255));
      brush1.setStyle(Qt::SolidPattern);
      palette.setBrush(QPalette::Inactive, QPalette::Button, brush1);
      QBrush brush2(QColor(190, 187, 184, 255));
      brush2.setStyle(Qt::SolidPattern);
      palette.setBrush(QPalette::Disabled, QPalette::Button, brush2);
      pushButton->setPalette(palette);
      @

      1 Reply Last reply
      0
      • EddyE Offline
        EddyE Offline
        Eddy
        wrote on last edited by
        #3

        And "here":http://qt-project.org/doc/qt-4.8/stylesheet-examples.html#customizing-a-qpushbutton-using-the-box-model
        Is a well explained stylesheet example

        Qt Certified Specialist
        www.edalsolutions.be

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sczhengyabin
          wrote on last edited by
          #4

          Thanks for your reply.
          Yes, I know this could work for colors in stylesheet.
          But I want use pictures instead of colors.
          As I said, I only have two pngs , "A" for state Normal, and "B" for sate Pressed. I know that the Qt can grey a button icon (a png file set for this icon) when a button is disabled. So I want the disabled state for the button has icon of a greyed "A".
          Any solution?
          Thanks.
          [quote author="andreyc" date="1395417004"]Here is an example that I've got from designer.
          It creates a new QPushButton and sets different colours for active, inactive and disabled state.
          @
          pushButton = new QPushButton(widgetPlayback);
          pushButton->setObjectName(QStringLiteral("pushButton"));
          pushButton->setGeometry(QRect(110, 210, 80, 23));
          QPalette palette;
          QBrush brush(QColor(54, 239, 156, 255));
          brush.setStyle(Qt::SolidPattern);
          palette.setBrush(QPalette::Active, QPalette::Button, brush);
          QBrush brush1(QColor(199, 239, 111, 255));
          brush1.setStyle(Qt::SolidPattern);
          palette.setBrush(QPalette::Inactive, QPalette::Button, brush1);
          QBrush brush2(QColor(190, 187, 184, 255));
          brush2.setStyle(Qt::SolidPattern);
          palette.setBrush(QPalette::Disabled, QPalette::Button, brush2);
          pushButton->setPalette(palette);
          @
          [/quote]

          1 Reply Last reply
          0
          • EddyE Offline
            EddyE Offline
            Eddy
            wrote on last edited by
            #5

            in the link i gave you: scroll down to the end and you will see this topic : QPushButton and images.

            Border-image is the key to your solution.

            You can use a border-image for the normal state and another one for the pressed state

            Qt Certified Specialist
            www.edalsolutions.be

            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