QGraphicsOpacityEffect Class
QGraphicsOpacityEffect 类提供了一种不透明度效果。更多内容...
| 头文件: | #include <QGraphicsOpacityEffect> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Widgets) target_link_libraries(mytarget PRIVATE Qt6::Widgets) |
| qmake: | QT += widgets |
| 继承自: | QGraphicsEffect |
属性
- opacity : qreal
- opacityMask : QBrush
公共函数
| 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 |
另请参阅 QGraphicsDropShadowEffect 、QGraphicsBlurEffect 以及QGraphicsColorizeEffect 。
属性文档
opacity : qreal
该属性控制效果的不透明度。
该值应在 0.0 到 1.0 之间,其中 0.0 表示完全透明,1.0 表示完全不透明。
默认情况下,不透明度为 0.7。
访问函数:
| qreal | opacity() const |
| void | setOpacity(qreal opacity) |
通知信号:
| 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`的通知器 信号。
© 2026 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.
