Details
-
Bug
-
Resolution: Incomplete
-
P2: Important
-
None
-
5.5.1
-
None
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
Issue Links
- is replaced by
-
QTBUG-38760 WA_TranslucentBackground dont repaint on MacOSX
- Reported