Skip to content

Commit

Permalink
Set sharedPainter correctly for QGraphicsEffect
Browse files Browse the repository at this point in the history
Autotest is taken from the previously reverted
8b1377f.

Task-number: QTBUG-60231
Change-Id: I44dd79cba22b6baefdd6d95c176790bef0b7eafe
Reviewed-by: Andy Nichols <[email protected]>
  • Loading branch information
alpqr committed Dec 12, 2017
1 parent 6a5ca72 commit 7257862
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/widgets/kernel/qwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5528,11 +5528,11 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP
setSystemClip(pdev, rgn.translated(offset));
QPainter p(pdev);
p.translate(offset);
context.painter = &p;
context.painter = context.sharedPainter = &p;
graphicsEffect->draw(&p);
setSystemClip(pdev, QRegion());
} else {
context.painter = sharedPainter;
context.painter = context.sharedPainter = sharedPainter;
if (sharedPainter->worldTransform() != sourced->lastEffectTransform) {
sourced->invalidateCache();
sourced->lastEffectTransform = sharedPainter->worldTransform();
Expand Down
21 changes: 21 additions & 0 deletions tests/auto/widgets/effects/qgraphicseffect/tst_qgraphicseffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ private slots:
void boundingRect2();
void draw();
void opacity();
void nestedOpaqueOpacity();
void grayscale();
void colorize();
void drawPixmapItem();
Expand Down Expand Up @@ -407,6 +408,26 @@ void tst_QGraphicsEffect::opacity()
QCOMPARE(effect->m_opacity, qreal(0.5));
}

void tst_QGraphicsEffect::nestedOpaqueOpacity()
{
// QTBUG-60231: Nesting widgets with a QGraphicsEffect on a toplevel with
// QGraphicsOpacityEffect caused crashes due to constructing several
// QPainter instances on a device in the fast path for
// QGraphicsOpacityEffect::opacity=1
QWidget topLevel;
topLevel.setWindowTitle(QTest::currentTestFunction());
topLevel.resize(320, 200);
QGraphicsOpacityEffect *opacityEffect = new QGraphicsOpacityEffect;
opacityEffect->setOpacity(1);
topLevel.setGraphicsEffect(opacityEffect);
QWidget *child = new QWidget(&topLevel);
child->resize(topLevel.size() / 2);
QGraphicsDropShadowEffect *childEffect = new QGraphicsDropShadowEffect;
child->setGraphicsEffect(childEffect);
topLevel.show();
QVERIFY(QTest::qWaitForWindowExposed(&topLevel));
}

void tst_QGraphicsEffect::grayscale()
{
if (qApp->desktop()->depth() < 24)
Expand Down

0 comments on commit 7257862

Please sign in to comment.