2 Attachment(s)
Left align the items on Zommout
When doing zoomIn, zoom happens on left aligned (item on top left is always visible) but on zoom out items going to the center of the view by leaving lot of space on left,
I want all items should be left aligned on zoom out also.
Code for LeftAigned ZoomIn.
Code:
{
if ((event->modifiers()&Qt::ControlModifier) == Qt::ControlModifier
&& event->angleDelta().x() == 0)
{
QPointF posf
= this
->mapToScene
(pos
);
double angle = event->angleDelta().y();
double scalingFactor;
if(angle > 0)
{
scalingFactor = 1 + ( angle / 360 * 0.1);
}else if (angle < 0)
{
scalingFactor = 1 - ( -angle / 360 * 0.1);
} else
{
scalingFactor = 1;
}
m_pvtData->m_scale = scalingFactor;
this->scale(scalingFactor, scalingFactor);
double w = this->viewport()->width();
double h = this->viewport()->height();
double wf
= this
->mapToScene
(QPoint(w
-1,
0)).
x() - this
->mapToScene
(QPoint(0,
0)).
x();
double hf
= this
->mapToScene
(QPoint(0, h
-1)).
y() - this
->mapToScene
(QPoint(0,
0)).
y();
double lf = posf.x() - pos.x() * wf / w;
double tf = posf.y() - pos.y() * hf / h;
/* try to set viewport properly */
this->ensureVisible(lf, tf, wf, hf);
QPointF newPos
= this
->mapToScene
(pos
);
}
if ((event->modifiers()&Qt::ControlModifier) != Qt::ControlModifier) {
}
event->accept();
}
Re: Left align the items on Zommout
I am not sure about this (years since I have done anything with QGraphicsView - but I'd try setting the view alignment to top left:
http://doc.qt.io/qt-5/qgraphicsview.html#alignment-prop
If this does not help, I'd experiment with the viewport anchor:
http://doc.qt.io/qt-5/qgraphicsview....ionAnchor-prop
Please share here if you have solved it and how.