Use qtgraphicaleffects to make your image display more vivid

Source: Internet
Author: User
Tags transparent color

Interested developers can refer to the link http://doc.qt.io/qt-5/qtgraphicaleffects-qmlmodule.html to learn more about QT's processing of graphics. In today's article, let's use OpacityMask to do a little bit of an example to see how QT handles our images. Specific examples can be found on the official website of QT. For some reason, the files in the routine downloaded on the official website are not available and need to be processed.


Below, we are going to show you our example directly:


Import QtQuick 2.0import ubuntu.components 1.1import qtgraphicaleffects 1.0/*! \brief MainView with a Label and Button Elements.*/mainview {//ObjectName for functional testing purposes (autopilot- QT5) ObjectName: "MainView"//note! ApplicationName needs to match the "name" field of the click Manifest ApplicationName: "Mask.liu-xiao-guo"/* Th Is property enables the application to change orientation when the device is rotated.    The default is False.    *///automaticorientation:true//Removes the old toolbar and enables new features of the new header.        Usedeprecatedtoolbar:false width:units.gu (height:units.gu) page {title:i18n.tr ("mask")                flickable {anchors.fill:parent contentHeight:mypics.childrenRect.height Item {                    Id:mypics width:parent.width Height:units.gu (+) Image { Id:bug hEIGHT:PARENT.HEIGHT/2 width:height Source: "Images/bug.png" sou                RceSize:Qt.size (Parent.width, parent.height) smooth:true Visible:false } Image {Id:bug1 HEIGHT:PARENT.HEIGHT/2 wi Dth:height Source: "Images/bug.png" Anchors.top:bug.bottom anch Ors.topMargin:units.gu (1) sourceSize:Qt.size (parent.width, parent.height) Smooth:                    True Visible:false} Rectangle {Id:mask                    Anchors.margins:10 width:65 height:65 color: "BLACK"                RADIUS:WIDTH/2 Clip:true Visible:false}         Image {           Id:mask1 Height:units.gu (+) Width:height Source: "                    Images/bufferfly.png "SourceSize:Qt.size (Parent.width, Parent.height) smooth:true                    Visible:false} opacitymask {Anchors.fill:bug                    Source:bug Masksource:mask} opacitymask {        Anchors.fill:bug1 Source:bug Masksource:mask1}} }    }}

Here we use the image to display the picture, but they are not visible (Visible = False). We can pass a mask mask, where it defines the transparent color of the area can be opacitymask to enable them to display.

Our mask image bufferfly.png is as follows:




Bug.png's original image is:



Run our routines as follows:




SOURCE in: Git clone https://gitcafe.com/ubuntu/mask.git

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Use qtgraphicaleffects to make your image display more vivid

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.