QCanvas clipping problems
I need to be able to clip my canvas to a given rectangle. I tried sub-classing from the QCanvas widget and added my own virtual functions for drawForeground and drawBackground. I then tried to set clipping on and set a clip rect for the painter in both functions, which didn't work.
So then I tried to just add a return statement at the top of both functions, but the foreground always gets painted.
Can someone tell me what I am doing wrong, and more importantly, why is it drawing anything at all when I am just returning from the draw functions?
Re: QCanvas clipping problems
I think it will be easiest if you reimplement drawContents() from QCanvasView. There you can clip the painter to a desired rectangle and call the base class implementation.
Re: QCanvas clipping problems
Yeah that's what I thought too. Here is what I tried, which still draw the entire canvas:
void myCanvasView::drawContents(QPainter *p, int cx, int cy, int cw, int ch)
{
QRect myRect(20, 20, 50, 50);
p->setClipRect(myRect);
p->setClipping(true);
QCanvasView::drawContents(p, myRect.x(), myRect.y(), myRect.width(), myRect.height());
}
Re: QCanvas clipping problems
You should certainly call the base class implementation with the values you received, so cx, cy, cw and ch in this case. And check if your implementation is called at all.
Re: QCanvas clipping problems
No, you should call the base class version with the values you clip the painter: 20, 20, 50 ,50.
Re: QCanvas clipping problems
Quote:
Originally Posted by
marcel
No, you should call the base class version with the values you clip the painter: 20, 20, 50 ,50.
Hmm... Why so?