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

Graphics effects break opacity propagation

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.14.0
    • GUI: Painting
    • None
    • Windows

    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;
      }
      
      
      

      Attachments

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

        Activity

          People

            vgt Eirik Aavitsland
            loganmcbroom Logan McBroom
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes