Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
src_gui_effects_qgraphicseffect.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4//! [0]
5MyGraphicsOpacityEffect::draw(QPainter *painter)
6{
7 // Fully opaque; draw directly without going through a pixmap.
8 if (qFuzzyCompare(m_opacity, 1)) {
9 drawSource(painter);
10 return;
11 }
12 ...
13}
14//! [0]
15
16//! [1]
17MyGraphicsEffect::draw(QPainter *painter)
18{
19 ...
20 QPoint offset;
21 if (sourceIsPixmap()) {
22 // No point in drawing in device coordinates (pixmap will be scaled anyways).
23 const QPixmap pixmap = sourcePixmap(Qt::LogicalCoordinates, &offset);
24 ...
25 painter->drawPixmap(offset, pixmap);
26 } else {
27 // Draw pixmap in device coordinates to avoid pixmap scaling;
28 const QPixmap pixmap = sourcePixmap(Qt::DeviceCoordinates, &offset);
29 painter->setWorldTransform(QTransform());
30 ...
31 painter->drawPixmap(offset, pixmap);
32 }
33 ...
34}
35//! [1]
36
37//! [2]
38...
39QLinearGradient alphaGradient(rect.topLeft(), rect.bottomLeft());
40alphaGradient.setColorAt(0.0, Qt::transparent);
41alphaGradient.setColorAt(0.5, Qt::black);
42alphaGradient.setColorAt(1.0, Qt::transparent);
43QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect;
44effect->setOpacityMask(alphaGradient);
45...
46//! [2]
\inmodule QtGui
Definition qbrush.h:416
QGraphicsOpacityEffect * effect
the effect attached to this item