c++ - Qt update() doesn't work -
i have problem , update() function in qgraphicsitem
doesn't work. want , when move circle , other qgraphicsitem
( in mean time roundrect ) changes color. example, want do:
circle.cpp:
void circleitem::mousemoveevent(qgraphicsscenemouseevent *event) { // roundrect object rectitem->setbackground(); qgraphicsitem::mousemoveevent( event ); }
roundrect.cpp:
void roundrectitem::setbackground() { changebackground = true; update(); } void roundrectitem::paint(qpainter *painter, const qstyleoptiongraphicsitem *option, qwidget *widget) { qrectf rec = qrectf( qpoint( 0,0 ), boundingrect().size() / 2 ); roundrect = qrectf(rec.adjusted(-rec.height() / 2, 0, rec.height()/2, 0)); roundrect.moveto( boundingrect().center().x() - roundrect.width() / 2, boundingrect().center().y() - roundrect.height() / 2 ); if( !changebackground ) painter->setbrush( backbrush ); else painter->setbrush( qbrush( qt::blue ) ); painter->setpen( qcolor( 255,255,255 ) ); painter->drawroundedrect(roundrect, roundrect.height() / 2, roundrect.height() / 2 ); }
so question is, how can make update()
work right.
you invoking update() method of qgraphicsitem. should call update() of qgraphicsview working with. example can keep qgraphicsview member class of item like:
qgraphicsview * parent;
and call it's update method when want changes take place like:
void roundrectitem::setbackground() { changebackground = true; parent->update(); }
Comments
Post a Comment