c++ - Calling Qpainter's method paint to refresh image and change color -
i have created object call player
inherits qgraphicsobject
.
what trying change image of player , colour of bounding shape when click on mouse. thing don't know values send player->paint()
update image.
i override 2 pure virtual functions follows
in player.h :
class player : public qgraphicsobject { public: player(); qrectf boundingrect() const; qpainterpath shape() const; void paint(qpainter *painter, const qstyleoptiongraphicsitem *option,qwidget *widget); void mousepressevent(qgraphicsscenemouseevent *event); }
in player.cpp
player::player() { qpixmap m_playerpixmap(":/images/images/chevalier/test1.png"); } qrectf player::boundingrect() const { return qrectf(-15, 0, 128, 130); } qpainterpath player::shape() const { qpainterpath path; path.addellipse(-15, 70, 100, 60); return path; } void player::paint(qpainter *painter, const qstyleoptiongraphicsitem *option,qwidget *widget) { qpen linepen; linepen.setwidth(5); linepen.setcolor(qt::red); painter->setpen(linepen); painter->drawpath(shape()); painter->drawpixmap(0, 0, m_playerpixmap); } void player::mousepressevent(qgraphicsscenemouseevent *event) { this->paint(); }
thanks lot help.
you have call update()
.
this mark item updated, , issue paint event, call paint
correct parameters
Comments
Post a Comment