QGraphicsOpacityEffect Class

QGraphicsOpacityEffect 类提供了一种不透明效果。更多

头文件: #include <QGraphicsOpacityEffect>
CMake: find_package(Qt6 REQUIRED COMPONENTS Widgets)
target_link_libraries(mytarget PRIVATE Qt6::Widgets)
qmake: QT += widgets
继承: QGraphicsEffect

属性

公共功能

QGraphicsOpacityEffect(QObject *parent = nullptr)
virtual ~QGraphicsOpacityEffect()
qreal opacity() const
QBrush opacityMask() const

公共插槽

void setOpacity(qreal opacity)
void setOpacityMask(const QBrush &mask)

信号

void opacityChanged(qreal opacity)
void opacityMaskChanged(const QBrush &mask)

重新实现的受保护函数

virtual void draw(QPainter *painter) override

详细说明

不透明效果会以不透明的方式渲染信号源。这种效果适用于使信号源半透明,类似于淡入/淡出序列。可以使用setOpacity() 函数修改不透明度。

默认情况下,不透明度为 0.7。

另请参阅 QGraphicsDropShadowEffect,QGraphicsBlurEffect, 和QGraphicsColorizeEffect

属性文档

opacity : qreal

此属性表示效果的不透明度。

数值范围应在 0.0 至 1.0 之间,其中 0.0 表示完全透明,1.0 表示完全不透明。

默认情况下,不透明度为 0.7。

访问功能:

qreal opacity() const
void setOpacity(qreal opacity)

Notifier 信号:

void opacityChanged(qreal opacity)

另请参见 setOpacityMask().

opacityMask : QBrush

该属性用于保存效果的不透明度掩码。

不透明度遮罩允许你将不透明度应用到元素的某些部分。

例如

...
QLinearGradient alphaGradient(rect.topLeft(), rect.bottomLeft());
alphaGradient.setColorAt(0.0, Qt::transparent);
alphaGradient.setColorAt(0.5, Qt::black);
alphaGradient.setColorAt(1.0, Qt::transparent);
QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect;
effect->setOpacityMask(alphaGradient);
...

默认情况下没有不透明度遮罩。

访问功能:

QBrush opacityMask() const
void setOpacityMask(const QBrush &mask)

通知信号:

void opacityMaskChanged(const QBrush &mask)

另请参阅 setOpacity().

成员函数文档

QGraphicsOpacityEffect::QGraphicsOpacityEffect(QObject *parent = nullptr)

构造一个新的 QGraphicsOpacityEffect 实例。parent 参数传递给QGraphicsEffect 的构造函数。

[virtual noexcept] QGraphicsOpacityEffect::~QGraphicsOpacityEffect()

破坏效果。

[override virtual protected] void QGraphicsOpacityEffect::draw(QPainter *painter)

重实现:QGraphicsEffect::draw(QPainter *painter).

[signal] void QGraphicsOpacityEffect::opacityChanged(qreal opacity)

每当特效的不透明度发生变化时,就会发出该信号。opacity 参数包含效果的新不透明度。

注: 属性opacity 的通知信号。

[signal] void QGraphicsOpacityEffect::opacityMaskChanged(const QBrush &mask)

每当效果的不透明度掩码发生变化时,就会发出该信号。mask 参数包含效果的新不透明度遮罩。

注: 属性opacityMask 的通知信号。

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.