PDA

View Full Version : Can QRubberBand paint out of clipping area ?



topoden
18th February 2010, 02:54
Hi guys,

I have a code (which I can not change) which uses QRubberBand in order to show boundaries on a chart. I need to implement custom display of the rubber band. The code (which, again, I can not change) gets an instance of rubber band to use at initialization time. This means that I can inherit from QRubberBand, reimplement paintEvent method and provide object of my class as the rubber. The only problem I have now is that I need somehow to paint on the area which is a bit bigger than QRubberBand geometry. When I do the painting out of the clipping rectangle, its being clipped. So the question is actually, how can I access the clipping area which is used by painter. QPainter::setClipRect does not help :(

Here is something close to what I'm trying to do (just to make it a bit clearer):



void MyRubberBand::paintEvent(QPaintEvent * e)
{
QPainter painter(this);
QRect rect = e->rect();
rect.adjust(-10, -10, 10, 10);

painter.save();
painter.setClipRect(rect);
painter.fillRect(rect, Qt::blue);
painter.restore();
}


The code above will try to display blue rectangle which is 20 pixels greater in each dimention than the e->rect() (which I believe, is the clip rectangle). But the rectangle will be displayed clipped

Any ideas ?

aamer4yu
18th February 2010, 08:24
What does your application do ? I dont see any need to QRubberBand.QRubberBand is usually used while making selections.
From your post it seems you have a area / canvas thing on which user can draw. Am I getting it right ?

topoden
18th February 2010, 14:43
What does your application do ? I dont see any need to QRubberBand.QRubberBand is usually used while making selections.
From your post it seems you have a area / canvas thing on which user can draw. Am I getting it right ?

Not exactly, the application shows graph charts. User can soom-in / zoom-out by selecting an area on the chart. I use KDChart library to display the chart, and the KDChart library in its turn uses QRubberBand for displaying the zooming area. In my task Y axis zooming should be disabled. I managed to make KDChart to disable Y axis zoom, but the rubber area is still displayed as a rectangle, not as two parallel vertical lines (well, I want to display it as a semitransparent rectangle with height of the full chart and width as specified by used via mouse click/drag-drop). I can display the rubber as I want but the result picture is then being clipped. I want to somehow disable / tweak this clipping.

So just to reiterate:
1. I have to use QRubberBand (its already used and I can not do anything with this)
2. The only direction to go for me seems to be inheriting from QRubberBand and reimplementing paintEvent
3. To make all that I need to disable QPainter clipping. But I can not find a way to do that.

Hope its clearer now.