QGraphicsEffect介绍(十分漂亮)

 

QGraphicsEffect也是Qt-4.6引入的一个新功能。它让给图形元素QGraphicsItem增加更佳视觉效果的编程变得非常简单。

先来看几张效果图。

QGraphicsEffect介绍(十分漂亮)
QGraphicsEffect介绍(十分漂亮) QGraphicsEffect介绍(十分漂亮)
QGraphicsEffect介绍(十分漂亮) QGraphicsEffect介绍(十分漂亮)

上图中最上面的那个图片是没有使用QGraphicsEffect处理的原图,下面的四个图片分别代表了模糊,变色,透明和阴影效果。对应使用了QGraphicsEffect的4个子类QGraphicsBlurEffect, QGraphicsColorizeEffect, QGraphicsDropShadowEffect, 和 QGraphicsOpacityEffect.下面分别介绍它们。

QGraphicsBlurEffect
该类用应产生模糊效果,主要函数setBlurRadius(qreal blurRadius),用于控制图形元素的模糊度,数值越大越模糊。使用该类例子如下

QGraphicsBlurEffect *e0 = new QGraphicsBlurEffect(this);
e0->setBlurRadius(0.2);
item[0]->setGraphicsEffect(e1);//item[0] 为QGraphicsItem指针

QGraphicsColorizeEffect
该类提供了使用另外一种颜色对当前图形的一种着色功能。主要函数是setColor(QColor)和setStrength (qreal strength),指定了着色和着色强度。使用该类例子如下

QGraphicsColorizeEffect *e1 = new QGraphicsColorizeEffect(this);
e1->setColor(QColor(0,0,192));
item[1]->setGraphicsEffect(e1);

QGraphicsDropShadowEffect
该类提供了图形元素的阴影效果,用于增加立体感。主要设置函数有3个,setColor()用于设定阴影的颜色,setBlurRadius()用于设定阴影的模糊度,setOffset (qreal dx,qreal dy)用于设定在哪个方向产生阴影效果,如果dx为负数,则阴影在图形元素的左边。使用该类例子如下

QGraphicsDropShadowEffect *e2 = new QGraphicsDropShadowEffect(this);
e2->setOffset(8,8);
item[2]->setGraphicsEffect(e2);

QGraphicsOpacityEffect
该类用于图形元素的透明效果,主要函数是setOpacity(qreal opacity),用于设置透明度,参数值在0和1.0之间。也可以设置部分透明效果,需要调用的函数是setOpacityMask (QBrush mask)。使用该类例子如下

QGraphicsOpacityEffect *e3 = new QGraphicsOpacityEffect(this);
e3->setOpacity(0.7);
item[3]->setGraphicsEffect(e3);

下面我是写的例子代码和截图。

QGraphicsEffect介绍(十分漂亮)

最后值得一提的是,这些效果是可以互相组合的。如果能把这些效果和Qt的动画Animation API结合起来,写出的程序就更漂亮了。
$QTSRC/examples/effect目录下面有些例子可以参考。

Tags: Qt4.6特效
This entry was posted on Saturday, February 6th, 2010 at 10:43 PM and is filed under C++Qt技术. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, ortrackback from your own site.

One Response to “Qt 图形特效(Graphics Effect)介绍”

http://cowboy.1988.blog.163.com/blog/static/75105798201151311244982/

原文链接: https://www.cnblogs.com/findumars/p/5979128.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    QGraphicsEffect介绍(十分漂亮)

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/242391

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月13日 下午10:20
下一篇 2023年2月13日 下午10:22

相关推荐