[Development] scaling the background of QGraphicsView or QGraphicsScene

Sean Harmer sean.harmer at kdab.com
Sun Oct 2 11:10:42 CEST 2016


Hi,

use a cosmetic pen (width of zero).

Cheers,

Sean

On 02/10/2016 02:18, 心翔 wrote:
> Hi,
> I subclass the QGraphicsView to
> reimplement drawBackground and wheelEvent  and want to get  this effect:
>
>
> but when I wheel the mouse, the background point will scale also。
>
>> how can implement that it only scale t/he spacing between points but not
> the point itself,like this:/
> /
> /
> /
>> /
> /
> /
> /the code:/
>
>     voidSchView::wheelEvent(QWheelEvent*event)
>
>     {
>
>     qrealscaleFactor=(pow((double)2,event->delta()/240.0));
>
>     qrealfactor=transform().scale(scaleFactor,scaleFactor).mapRect(QRectF(0,0,1,1)).width();
>
>
>     if(factor<0.07||factor>100)
>
>     return;
>
>
>     scale(scaleFactor,scaleFactor);
>
>     }
>
>
>     voidSchView::drawBackground(QPainter*painter,constQRectF&rect)
>
>     {
>
>     intgridSize=20;
>
>     QPenpen(QColor(Qt::white));
>
>     painter->setPen(pen);
>
>
>     qrealleft=int(rect.left())-(int(rect.left())%gridSize);
>
>     qrealtop=int(rect.top())-(int(rect.top())%gridSize);
>
>
>     QVarLengthArray<QPointF,800>points;
>
>     for(qrealx=left;x<rect.right();x+=gridSize){
>
>     for(qrealy=top;y<rect.bottom();y+=gridSize){
>
>     points.append(QPointF(x,y));
>
>     }
>
>     }
>
>     painter->drawPoints(points.data(),points.size());
>
>     }
>
>
>
>
> /
> /
> /Any suggestions are greatly appreciated./
> /thanks/
> /
> /
> /
> /
> /
> /
> ------------------------------------------------------------------------
> itviewer
> /
> /
>
>
> _______________________________________________
> Development mailing list
> Development at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/development
>

-- 
Dr Sean Harmer | sean.harmer at kdab.com | Managing Director UK
KDAB (UK) Ltd, a KDAB Group company
Tel. +44 (0)1625 809908; Sweden (HQ) +46-563-540090
Mobile: +44 (0)7545 140604
KDAB - Qt Experts



More information about the Development mailing list