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:*

> void SchView::wheelEvent(QWheelEvent *event)
>
> {
>
>     qreal scaleFactor = (pow((double)2, event->delta() / 240.0));
>
>     qreal factor = transform().scale(scaleFactor, 
> scaleFactor).mapRect(QRectF(0, 0, 1, 1)).width();
>
>
>     if (factor < 0.07 || factor > 100)
>
>         return;
>
>
>     scale(scaleFactor, scaleFactor);
>
> }
>
>
void SchView::drawBackground(QPainter *painter, const QRectF &rect)
>
> {
>
>     int gridSize = 20;
>
>     QPen pen(QColor(Qt::white));
>
>     painter->setPen(pen);
>
>
>     qreal left = int(rect.left()) - (int(rect.left()) % gridSize);
>
>     qreal top = int(rect.top()) - (int(rect.top()) % gridSize);
>
>
>     QVarLengthArray<QPointF, 800> points;
>
>     for (qreal x = left; x < rect.right(); x += gridSize){
>
>         for (qreal y = 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
[email protected]
http://lists.qt-project.org/mailman/listinfo/development

Reply via email to