c++ - Fill the QRect on enter event -
i have task: qrect object should painted when mouse cursor entering it. after couple of hours made this.
void myobj::mousemoveevent(qmouseevent* event){ int x1, y1, x2, y2; qpoint point = event->pos(); rect->getcoords(&x1, &y1, &x2, &y2); if((point.x() >= x1) && (point.x() <= x2) && (point.y() >= y1) && (point.y() <= y2)){ changerectcolour(); }else{ brush->setcolor(qt::green); repaint(); } }
myobj inherited qwidget. think idea isn't efficient. because on every mouse move outside qrect changes color green(even if it's green). unfortunatelly, qrect hasn't enterevent() function. can you, please, give advice how properly.
qwidget::repaint()
means "paint now!!! can't wait!". use qwidget::update() instead, fold several paint requests 1 (better explanation in doc).
btw reimplementing qrect::contains()
. new code be
void myobj::mousemoveevent(qmouseevent* event){ qpoint point = event->pos(); if(rect->contains(point, true)){ changerectcolour(); } else{ brush->setcolor(qt::green); update(); } }
Comments
Post a Comment