Qt 图形特效(Graphics Effect)介绍
原文鏈接:Qt 圖形特效(Graphics Effect)介紹
?
QGraphicsEffect也是Qt-4.6引入的一個新功能。它讓給圖形元素QGraphicsItem增加更佳視覺效果的編程變得非常簡單。
先來看幾張效果圖。
上圖中最上面的那個圖片是沒有使用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);
下面我是寫的例子代碼和截圖。
最后值得一提的是,這些效果是可以互相組合的。如果能把這些效果和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.
轉載于:https://www.cnblogs.com/lvdongjie/p/4366086.html
總結
以上是生活随笔為你收集整理的Qt 图形特效(Graphics Effect)介绍的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2021-2027全球与中国MSMS探针
- 下一篇: ios验证邮箱格式