hi friends,
I just drawn grid lines in the QGraphicsView on its
{
QVarLengthArray<QLineF, 100> linesX;
for (qreal x = left; x < sceneRect.right(); x += gridInterval )
{
linesX.
append(QLineF(x, sceneRect.
top(), x, sceneRect.
bottom()));
}
QVarLengthArray<QLineF, 100> linesY;
for (qreal y = top; y < sceneRect.bottom(); y += gridInterval ){
linesY.
append(QLineF(sceneRect.
left(), y, sceneRect.
right(), y
));
}
painter->drawLines(linesX.data(), linesX.size());
painter->drawLines(linesY.data(), linesY.size());
}
drawbackground(QPainter *painter, const QRectF &rect)
{
QVarLengthArray<QLineF, 100> linesX;
for (qreal x = left; x < sceneRect.right(); x += gridInterval )
{
linesX.append(QLineF(x, sceneRect.top(), x, sceneRect.bottom()));
}
QVarLengthArray<QLineF, 100> linesY;
for (qreal y = top; y < sceneRect.bottom(); y += gridInterval ){
linesY.append(QLineF(sceneRect.left(), y, sceneRect.right(), y));
}
painter->drawLines(linesX.data(), linesX.size());
painter->drawLines(linesY.data(), linesY.size());
}
To copy to clipboard, switch view to plain text mode
and im scaling the view by
{
if(event->modifiers().testFlag(Qt::ControlModifier))
{
int numSteps = event->delta() / 15/ 8;
if (numSteps == 0)
{
event->ignore();
return;
}
qreal sc = pow(1.25, numSteps);
qreal factor = transform().scale(scaleFactor, scaleFactor).mapRect(r).width();
if(factor < 1)
return;
this->scale(scaleFactor, scaleFactor);
event->accept();
}
}
wheelEvent(QWheelEvent *event)
{
if(event->modifiers().testFlag(Qt::ControlModifier))
{
int numSteps = event->delta() / 15/ 8;
if (numSteps == 0)
{
event->ignore();
return;
}
qreal sc = pow(1.25, numSteps);
QRectF r(0, 0, 1, 1);
qreal factor = transform().scale(scaleFactor, scaleFactor).mapRect(r).width();
if(factor < 1)
return;
this->scale(scaleFactor, scaleFactor);
event->accept();
}
}
To copy to clipboard, switch view to plain text mode
now how i can ignore the grid lines not to be scaled .
as u can see even the grid lines also getting scaled every time i zoom .
if it is a graphicsItem i can use ignore transform but for normal painter ..?
i tried QPainter::resetTransform() but in vain ..
Please help me ..
Bookmarks