Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.14.0
-
None
Description
This could be intended behavior, I am not entirely sure how graphics effects interact with the opacity property. When a graphics effect is added to a QGraphicsObject, child graphics objects take on the opacity of the affected object regardless of the ItemIgnoresParentOpacity flag. Here is a basic MainWindow.cpp that shows the problem.
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QtWidgets> class Transparent : public QGraphicsObject { public: Transparent() : opaque( new QGraphicsProxyWidget( this ) ) { setOpacity(0.2); //This breaks it setGraphicsEffect( new QGraphicsDropShadowEffect ); opaque->setWidget( new QPushButton( "Hello Opaque" ) ); opaque->setOpacity( 1.0 ); opaque->setFlag( QGraphicsItem::ItemIgnoresParentOpacity, true ); } virtual QRectF boundingRect() const { return QRectF( 0, 0, 250, 250 ); } virtual void paint( QPainter * painter, const QStyleOptionGraphicsItem *, QWidget * ) { painter->fillRect( 0, 0, 250, 250, QColor::fromHsl( 0, 0, 255 ) ); } QGraphicsProxyWidget * opaque; }; MainWindow::MainWindow( QWidget *parent ) : QMainWindow( parent ) , ui( new Ui::MainWindow ) { ui->setupUi(this); auto scene = new QGraphicsScene( this ); scene->addItem( new Transparent ); auto view = new QGraphicsView( this ); view->setBackgroundBrush( Qt::black ); view->setScene( scene ); view->setFixedSize( 500, 500 ); } MainWindow::~MainWindow() { delete ui; }