Qt Graphics Effects (Graphics Effect) Introduction to __qt/graphics images

Source: Internet
Author: User

all the articles by this site and the original author reserves all the rights, only in the preservation of the copyright information, the original link, the original author of the case allows reprint, reproduced do not be deleted text content, and may not be used for commercial purposes. Thank you for your cooperation. text Link: Qt Graphics special effects (Graphics Effect) Introduction

Qgraphicseffect is also a new feature introduced by Qt-4.6. It is easy to give graphical elements Qgraphicsitem programming to add better visual effects.

Let's take a look at some of the effects.

The top of the picture above is not using qgraphicseffect processing of the original image, the following four pictures represent the blur, discoloration, transparency and shadow effects. Corresponds to the use of the Qgraphicseffect 4 subclasses Qgraphicsblureffect, Qgraphicscolorizeeffect, Qgraphicsdropshadoweffect, and Qgraphicsopacityeffect. Introduce them separately below.

Qgraphicsblureffect
This class should produce fuzzy effect, the main function Setblurradius (Qreal Blurradius), used to control the ambiguity of graphic elements, the larger the number of fuzzy. Use this class example as follows

Qgraphicsblureffect *e0 = new Qgraphicsblureffect (this);
E0->setblurradius (0.2);
Item[0]->setgraphicseffect (E1);//item[0] as Qgraphicsitem pointer

Qgraphicscolorizeeffect
This class provides a shading function for the current graphic using another color. The primary functions are SetColor (Qcolor) and setstrength (Qreal strength), which specify the coloring and shading intensities. Use this class example as follows

Qgraphicscolorizeeffect *e1 = new Qgraphicscolorizeeffect (this);
E1->setcolor (Qcolor (0,0,192));
Item[1]->setgraphicseffect (E1);

Qgraphicsdropshadoweffect
This class provides shadow effects for graphical elements to increase the icing on the stereo. The main setup functions are 3, setcolor () is used to set the color of the Shadow, Setblurradius () is used to set the blur of the Shadow, SetOffset (Qreal dx,qreal dy) is used to set the direction in which the shadow effect, if DX is negative, The shadow is on the left side of the graphic element. Use this class example as follows

Qgraphicsdropshadoweffect *e2 = new Qgraphicsdropshadoweffect (this);
E2->setoffset (8,8);
Item[2]->setgraphicseffect (E2);

Qgraphicsopacityeffect
This class is used for transparent effects of graphical elements, and the primary function is setopacity (qreal opacity), which is used to set transparency, with parameter values between 0 and 1.0. You can also set a partial transparency effect, and the function you need to call is Setopacitymask (Qbrush mask). Use this class example as follows

Qgraphicsopacityeffect *e3 = new Qgraphicsopacityeffect (this);
E3->setopacity (0.7);
Item[3]->setgraphicseffect (E3);

Below I am writing the example code and screenshot.

Finally, it is worth mentioning that these effects can be combined with each other. If you can combine these effects with QT's animated animation API, the programs you write are even more beautiful.
$QTSRC/examples/effect Directory There are some examples to refer to below.




From:http://blog.sina.com.cn/s/blog_66e717d70100hare.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.