Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-89652

setCompositionMode causes the window to be transparent

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.0.0
    • GUI: Painting
    • None
    • Linux/Wayland

    Description

      When we change the transparency of the image, drawing it onto the window will cause the window to be transparent.  

      void MainWindow::paintEvent(QPaintEvent *event)
      {
      
          QImage image("/home/thx/Desktop/3.png","png");
          QPainter pa(&image);
          pa.setCompositionMode(QPainter::CompositionMode_DestinationIn);
          pa.fillRect(image.rect(), QColor(0, 0, 0, 255 * 0.2));
          pa.end();
      
          QPainter painter(this);
          painter.drawImage(rect(),image);
      }
      

       

      The following code can also reproduce this problem

         QPainter paintertemp(this);
         QImage imgtmp(size(),QImage::Format::Format_RGB32);
         memset(imgtmp.bits(),0,imgtmp.sizeInBytes());
         
         paintertemp.drawImage(rect(),imgtmp);

       

      ==============================================================

      The study found that when test.png does not have a transparency attribute, the format of QImage is Format_RGB, and the use of fillRect changes the image transparency channel. When drawing, it will directly cover rasterBuffer and cause the background to be transparent.

       

      In fillrect(), should it be judged whether the PainterDevice has a transparent channel, instead of modifying it directly? 

      Attachments

        1. QTBUG-89652.png
          QTBUG-89652.png
          424 kB
        2. QTBUG-89652.zip
          5 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            vgt Eirik Aavitsland
            tanghaixiang haixiang tang
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes