A Sample Highlighting QGRAPHICSEFFECT__QT

Source: Internet
Author: User

Http://qt-project.org/wiki/Category:HowTo

Class   Highlighteffect:public qgraphicseffect
{
 q_object
 q_property (qcolor  color   READ Color  WRITE setcolor)
 q_property (qpointf offset  READ offset WRITE setoffset) public
:
 Highlighteffect (qreal offset = 1.5);
 Virtual QRECTF  boundingrectfor (const QRECTF &sourceRect;) const;
 Qcolor          Color () const {return Mcolor}
 void            SetColor (Qcolor &color;) {mcolor = color;}
 qpointf         offset () const {return moffset}
 void            setoffset (qpointf offset) {moffset = offset;}
 
Protected:
 virtual void    Draw (Qpainter *painter);//, Qgraphicseffectsource *source);
Private:
 qcolor              mcolor;
 qpointf             moffset;
};

 Highlighteffect::highlighteffect (qreal offset): Qgraphicseffect (), Mcolor (255, 255, 0, 128),//Yellow, Semi-tra 
Nsparent moffset (offset, offset) {} QRECTF highlighteffect::boundingrectfor (const QRECTF &sourceRect;) const
 
{return sourcerect.adjusted (-moffset.x (),-moffset.y (), Moffset.x (), Moffset.y ());}
 void Highlighteffect::d raw (Qpainter *painter) {qpoint offset;
 
Qpixmap Pixmap; if (Sourceispixmap ())//doesn ' t seems to work, return false {//No point in drawing in device coordinates (PIXMA
  P'll be scaled anyways).  Pixmap = Sourcepixmap (qt::logicalcoordinates, &offset;);
 , mode);
 
 } QRECTF bound = Boundingrectfor (Pixmap.rect ());
 Painter->save ();
 Painter->setpen (Qt::nopen);
 Painter->setbrush (Mcolor);
 qpointf P (offset.x ()-moffset.x (), Offset.y ()-moffset.y ());
 Bound.movetopleft (P);
 Painter->drawroundedrect (Bound, 5, 5, qt::relativesize);
 Painter->drawpixmap (offset, pixmap); Painter-&gT;restore (); }

        Pixmap *item = new Pixmap (KINETICPIX);
        Highlighteffect *effect = new Highlighteffect ();
 
        Item->setgraphicseffect (effect);


It is a good high light effect to make a record for the time being.

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.