drawing on coordinates built from visibleRegion() leave a trace on the screen
-
Hello,
I have a widget that contains a set of tiles, that together form a map.
The widget is scrollable in X and Y directions. Now I want to do custom drawing on the widget that stays always independent of scroll position on the same spot.
I am doing it based on the visibleRegion() method.QRegion visibleRegion = this->visibleRegion(); auto regionIt = visibleRegion.begin(); QRect visibleRect = *regionIt; int rightx = visibleRect.topRight().x() - 10; int topy = visibleRect.topRight().y() + 10; int leftx = rightx - widthOfNav; int bottomy = topy + heightOfNav; QRect navSquare = QRect(leftx, topy, widthOfNav, heightOfNav); painter->drawRect(navSquare);
But when I scroll the view, the drawing leaves a trace of the previously drawn rectangles. I thought that the draw routine was called for each scroll position and doing that I am overwriting all the pixels in the window because :
- I draw all the images visible (also using the visibleRegion() method
- I draw the rect on top of the images
Can anyone explain to me what is happening here ?
Thanks,
Regards -
Christian Ehrlicher Lifetime Qt Championreplied to Daniel Santos on last edited by Christian Ehrlicher
@Daniel-Santos said in drawing on coordinates built from visibleRegion() leave a trace on the screen:
Can anyone explain to me what is happening here ?
When you scroll only the new parts are painted when you don't invalidate others which you must when you want to draw something without the state of the current scroll position.
-
Got it. I connected two event handlers, each on the horizontal and vertical scrollers to repaint on scroll and it now works.
Thanks