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. Making QPushButton Icons Transparent.

Making QPushButton Icons Transparent.

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 1.0k 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.
  • M Offline
    M Offline
    mikeosoft
    wrote on last edited by
    #1

    Qt 5.15.1 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 5.3.1 20160406 (Red Hat 5.3.1-6)) on "xcb"
    OS: KDE neon User Edition 5.19 [linux version 5.4.0-48-generic]

    I've developed a little application that works, other than the fact that the transparent icons I've added are showing with the checked background rather than showing the button background.  The icons show bulbs and one is on and one is off and the application swaps them when I press the button to reflect the on/off state of the light it controls. You would change the selected light using a combobox.

    If I look at the icons in a file viewer they show as transparent images often do, with the checked background. I converted them from a non transparent background, so I can see the difference.

    This is what I did to make them Transparent:

    convert light-bulb-off.png -fuzz 1% -transparent white output1.png
    convert light-bulb-on.png -fuzz 1% -transparent white output2.png
    

    I'm using the same icons in two places, as an image on a button with no text and as icons in a combo-box were they would indicate the the individual state of each of the lights in the list. In both cases I want the transparent parts of the image and only those to be transparent, not the button or Combo-box. I want the user to see the widget background beneath the image.

    m_light_switch      = new QPushButton;
            m_light_switch->setIcon(QIcon(":/icons/light-bulb-off.png"));
            m_light_switch->setIconSize(QSize(840, 859));
            connect(m_light_switch, SIGNAL (released()),this, SLOT (switchpressed()));
            m_main_layout->addWidget(m_light_switch);
    

    If I load an icon with transparency as an application icon or within a menu, I have never had any problem getting it to display as I would expect, so I'm puzzling as to what I am doing wrong. any suggestions would be helpful.

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      This is not supported - the background is always drawn.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • Kent-DorfmanK Offline
        Kent-DorfmanK Offline
        Kent-Dorfman
        wrote on last edited by
        #3

        Of course there is nothing to prevent you from designing your own pushbutton witdget to meet the requirements. You just cannot base it upon QPushbutton. You may be able to base it upon QAbstractbutton though.

        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