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. Is it possible to set QLabel background color and add transparent image to it?
Forum Updated to NodeBB v4.3 + New Features

Is it possible to set QLabel background color and add transparent image to it?

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

    Hi,
    I would like to set QLabel's baground to red. Next I have transparent png image ( circle ). I would like to set this image to label and get red background and a circle on it:

    label.png

    When I write "transparent png image circle" I think about this:

    transparent.png

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      One way that comes to mind is to overwrite the paintEvent. In it fill the widget with red and then draw the image on top.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • A Offline
        A Offline
        AlexMaly
        wrote on last edited by AlexMaly
        #3

        I am not sure I understand the problem:

        • You can always set pixmap which may have transparent color (created from the image). In this case all you need to change background of the QLabel (for example using stylesheet)
        • Above way is good in most cases, but if your pixmap size is very different from label size, and you really want perfect look and scalability of the button you follow SGaist's suggestion and draw ellipse in the paint event instead using pixmap.
        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved