[Development] scaling the background of QGraphicsView or QGraphicsScene

itviewer assangema at gmail.com
Sun Oct 2 15:25:01 CEST 2016


Hi Sean,
Thank you very much, you helped me solve the problem that let me think for several days.
you are a good man!
 


itviewer
 
From: Sean Harmer
Date: 2016-10-02 17:10
To: development
Subject: Re: [Development] scaling the background of QGraphicsView or QGraphicsScene
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
_______________________________________________
Development mailing list
Development at qt-project.org
http://lists.qt-project.org/mailman/listinfo/development
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20161002/a2a49c08/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0.gif
Type: image/gif
Size: 1810 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20161002/a2a49c08/attachment.gif>


More information about the Development mailing list