qt - how to implement mouseEnter and mouseLeave event in QWidget? -


how implement mouseenter , mouseleave event in qwidget?

if mouseenter qwidget need set background color gray, if mouseleave qwidget need set background color white

i tried

void enterevent(qevent *); void leaveevent(qevent *); 

in inside of enter&leave event using bool varibale set true & false. , calling qpainter event update();

the code below:

void test::enterevent(qevent *) {    _mousemove=true;     update();  }  void test::leaveevent(qevent *) {    _mousemove=false;     update();  }  void test::paintevent(qpaintevent *) {     qpainter painter;     painter.begin(&m_targetimage);     painter.setrenderhint(qpainter::antialiasing);          if(_mousemove){             painter.fillrect(qrect(0,0,width(),height()),qt::white);}         else{             painter.fillrect(qrect(0,0,width(),height()),qt::gray);}      painter.end();      qpainter p;     p.begin(this);     p.drawimage(0, 0, m_targetimage);     p.end(); } 

i getting following error when moving mouse in qwidget

qpainter::begin: paint device returned engine == 0, type: 3 qpainter::setrenderhint: painter must active set rendering hints qpainter::end: painter not active, aborted 

please me fix this. if 1 having sample code please provide me....

first use member save current background color instead of boolean. simplify paintevent code:

painter.fillrect(qrect(...), m_backcolor); 

i guess errors appears first qpainter. why using qpainter fill image? if var qimage can use fill function example , call drawimage do. have same kind of function qpixmap.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -