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

Qt repaint issue for for translucent background on Mac, ghost image stays back

    XMLWordPrintable

Details

    • Bug
    • Resolution: Incomplete
    • P2: Important
    • None
    • 5.5.1
    • None
    • macOS

    Description

      I have drawn a QLabel (let's call it cart) within another QLabel (let's call it parent). The parent is drawn with translucent background. Whenever some file is dragged and dropped on the cart, it generates an OpenGL based image that sits inside the cart (let's call this image as child). There is a button clicking on which, the cart changes its orientation from portrait to landscape and vice versa. However, during flipping, the ghost image from the last orientation stays back.

      This is a known issue - https://bugreports.qt.io/browse/QTBUG-38760. I applied the fix, and it works fine for child images which are not OpenGL based.

      Any idea how to fix this issue? PFA the image of the ghost widget (the black one at the top is the cart in landscape mode now, while the ghost widget is still in portrait mode).

      This is the hack I applied on the parent widget's paintEvent:

      QPainter p( this );
      p.setCompositionMode( QPainter::CompositionMode_Clear );
      p.fillRect( this->rect(), Qt::transparent );
      

      Platform - Qt 5.3.1 32 bit and 5.5.1, 64 bit. OS X 10.10, Yosemite.

      Minimal reproducible example:

      main.cpp

      #include "mainwindow.h"
      #include <QApplication>
      #include "NoteParent.hpp"
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          NoteParent* n = new NoteParent();
          n->show();
      
          return a.exec();
      }
      

      NoteParent.hpp:

      class NoteParent: public QFrame
      {
          Q_OBJECT
      public:
          NoteParent();
          void paintEvent(QPaintEvent*);
      
      private:
          void prepareUI();
      
          Note *fNote;
      
      private slots:
          void animateNote(bool);
      
      };
      

      NoteParent.cpp:

      #include "NoteParent.hpp"
      #include "Note.hpp"
      #include <QIcon>
      #include <QDebug>
      #include <QPushButton>
      
      NoteParent::NoteParent()
      {
          prepareUI();
      }
      
      void NoteParent::prepareUI()
      {
          setFixedSize(200,200);
          setAttribute(Qt::WA_TranslucentBackground);
          setWindowFlags(Qt::FramelessWindowHint);
      
          fNote = new Note(this);
          fNote->move(30,10);
      
          QPushButton *fArrow = new QPushButton("F",this);
          fArrow->move(18,50);
          connect(fArrow,SIGNAL(clicked(bool)),this,SLOT(animateNote(bool)));
      }
      
      void NoteParent::animateNote(bool)
      {
          int h = fNote->height();
          fNote->setFixedHeight(h-20);
      
      }
      
      void NoteParent::paintEvent(QPaintEvent *)
      {
          QPainter p( this );
          p.setCompositionMode( QPainter::CompositionMode_Clear );
          p.fillRect( this->rect(), Qt::transparent );
      }
      

      Note.hpp:

      #pragma once
      
      #include <QFrame>
      
      class Note: public QFrame
      {
      public:
          Note(QWidget *parent = 0);
      };
      

      Note.cpp:

      #include "Note.hpp"
      
      Note::Note(QWidget *parent): QFrame(parent)
      {
          resize(160,130);
          setStyleSheet("background: rgb(242,242,242); border-radius: 8px;");
      }
      

      Normal state: normal.png
      After clicking the button, ghost.png is the result, there is a ghost image that juts out from below which should not.

      P.S After changing the height of Note, hiding and showing NoteParent fixes the ghost image issue. However, that is not acceptable solution in my case.

      Attachments

        1. Screen Shot 2016-01-28 at 11.13.22 AM.png
          Screen Shot 2016-01-28 at 11.13.22 AM.png
          1.10 MB
        2. ghost.png
          ghost.png
          84 kB
        3. normal.png
          normal.png
          189 kB

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              sorvig Morten Sørvig
              Cupidvogel Kaustav Mukherjee
              Veli-Pekka Heinonen Veli-Pekka Heinonen
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes