Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPixmap and Opacity and Transparency
Qt 6.12 LTS is out! See what's new in the release blog

QPixmap and Opacity and Transparency

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 13.3k 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
    shahriar25
    wrote on last edited by
    #1

    Hi,
    I want to know how to set the transparency and opacity of a pixmap. for example I want to set the opacity and transparency of a cover art to 50% and amke it a QListView's background image
    Can anyone tell me how to do this?

    1 Reply Last reply
    1
    • Ni.SumiN Offline
      Ni.SumiN Offline
      Ni.Sumi
      wrote on last edited by Ni.Sumi
      #2

      Hi @shahriar25 ,

      Try this,

      setAttribute(Qt::WA_TranslucentBackground, true);
      setWindowOpacity(0.5);

      1 Reply Last reply
      0
      • S Offline
        S Offline
        shahriar25
        wrote on last edited by
        #3

        Hi @Ni-Sumi
        Where sohuld I do this? to the main window? to the listview?

        1 Reply Last reply
        0
        • Ni.SumiN Offline
          Ni.SumiN Offline
          Ni.Sumi
          wrote on last edited by
          #4

          Hi @shahriar25 ,

          It is some thing like this,

          QPixmap input("YourImage.png");
          QImage image(input.size(), QImage::Format_ARGB32_Premultiplied); //Image with given size and format.
          image.fill(Qt::transparent); //fills with transparent
          QPainter p(&image);
          p.setOpacity(0.2); // set opacity from 0.0 to 1.0, where 0.0 is fully transparent and 1.0 is fully opaque.
          p.drawPixmap(0, 0, input); // given pixmap into the paint device.
          p.end();

          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
          • Unsolved