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

Transparency issue around winId() and QWebEngineView

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.6.0
    • WebEngine
    • None
    • Windows 8.1 x64 + Visual Studio 2015

    Description

      Assume we have a widget, which must be transparent. Its transparency is achieved by means of QGraphicsOpacityEffect. When the widget is shown on top of the QWebEngineView and the parent window contains some another widget, for which winId() was called, transparency effect doesn't work.

      The following code demonstrates the issue:

      main.cpp
      #include <QtCore>
      #include <QtWidgets>
      #include <QtWebEngineWidgets>
      #include <QGraphicsOpacityEffect> 
      
      class TransparentWindow : public QWidget
      {
      public:
      	TransparentWindow(QWidget *parent);
      protected:
      	virtual void paintEvent(QPaintEvent *event);
      };
      
      TransparentWindow::TransparentWindow(QWidget *parent)
      	: QWidget(parent, Qt::Widget | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint)
      {
      	resize(parent->width(), parent->height() / 2);
      	
      	QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect;
      	effect->setOpacity(0.5);
      	setGraphicsEffect(effect);
      }
      
      void TransparentWindow::paintEvent(QPaintEvent *event)
      {
      	QPainter painter(this);
      	
      	painter.setPen(Qt::NoPen);
      	painter.setBrush(QColor(200, 20, 20, 255));
      	painter.drawRoundedRect(painter.viewport(), 50, 50, Qt::AbsoluteSize);
      
      	painter.setPen(QColor(Qt::white));
      	painter.drawText(rect(), Qt::AlignCenter | Qt::TextWordWrap, "Transparency bug around child winId() and QWebEngineView");
      }
      
      
      int main(int argc, char * argv[])
      {
      	QApplication app(argc, argv);
      	
      	QMainWindow mw;
      	mw.resize(1000, 1000);
      	
      	QSplitter * splitter = new QSplitter(Qt::Horizontal);
      	
      	QWidget *child = new QWidget;
      	child->winId();	// ! Removing this line fixes the issue !
      
      	splitter->addWidget(child);
      	splitter->addWidget(new QWebEngineView);	// ! Replacing QWebEngineView with some another widget also fixes the issue !
      	//splitter->addWidget(new QWidget);
      	mw.setCentralWidget(splitter);
      	mw.show();
      	
      	// show the transparent popup
      	TransparentWindow *transparentWindow = new TransparentWindow(&mw);
      	transparentWindow->show();
      	
      	return app.exec();
      }
      

      The widget must be semi-transparent, but its right part (which is on top of the web view) is not transparent:

      If we replace QWebEngineView with some another widget or don't call winId() for another widget, transparency will work fine.

      The sample project is attached.

      Attachments

        1. testfading.zip
          20 kB
        2. transparency-bug.png
          transparency-bug.png
          12 kB
        3. transparent.png
          transparent.png
          12 kB

        Issue Links

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

          Activity

            People

              qt_webengine_team Qt WebEngine Team
              mentalmushroom Pugach Yaroslav
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes