zoom qwidget
Unsolved
General and Desktop
-
I'm having a problem with zooming on a qwidget, like when i zoom it zooms just on up left, and when i am trying to translate with the cursor position that is mapped from global i start to draw with an offset and the shapes moves with the cursor.
void Draw::paintEvent(QPaintEvent *event)
{
for(int i = 0; i < allShapes.size(); i++)
{QPainterPath path; path.moveTo(allShapes[i].getAllPoints()[0].getX(), allShapes[i].getAllPoints()[0].getY()); // we move the path to the first position for(int j = 1; j < allShapes[i].getAllPoints().size(); j++) if(allShapes[i].getAllPoints()[j].ge`enter code here`tType() == 'l' && allShapes[i].getAllPoints()[j-1].getType() != 'b') path.lineTo(allShapes[i].getAllPoints()[j].getX(), allShapes[i].getAllPoints()[j].getY()); else if(allShapes[i].getAllPoints()[j].getType() == 'b' && allShapes[i].getAllPoints()[j+1].getType() == 'b') { path.lineTo(allShapes[i].getAllPoints()[j-1].getX(), allShapes[i].getAllPoints()[j-1].getY()); path.cubicTo(allShapes[i].getAllPoints()[j].getX(), allShapes[i].getAllPoints()[j].getY(), allShapes[i].getAllPoints()[j+1].getX(), allShapes[i].getAllPoints()[j+1].getY(), allShapes[i].getAllPoints()[j+2].getX(), allShapes[i].getAllPoints()[j+2].getY()); } painter.translate(this->mapFromGlobal(QCursor::pos())); painter.scale(m_ScaleFactor.scaleX, m_ScaleFactor.scaleY); for(int i = 0; i < allShapes.size(); i++) for(int j = 1; j < allShapes[i].getAllPoints().size(); j++) { if(allShapes[i].getAllPoints()[j].getType() == 'l') painter.drawLine(allShapes[i].getAllPoints()[j-1].getX(), allShapes[i].getAllPoints()[j-1].getY(), allShapes[i].getAllPoints()[j].getX(), allShapes[i].getAllPoints()[j].getY()); if(allShapes[i].getAllPoints()[j].getType() == 'b' && allShapes[i].getAllPoints()[j-1].getType() == 'l') painter.drawLine(allShapes[i].getAllPoints()[j-1].getX(), allShapes[i].getAllPoints()[j-1].getY(), allShapes[i].getAllPoints()[j].getX(), allShapes[i].getAllPoints()[j].getY()); if(allShapes[i].getAllPoints()[j].getType() == 'b' && allShapes[i].getAllPoints()[j+1].getType() == 'b') { QPainterPath path; path.moveTo(allShapes[i].getAllPoints()[j-1].getX(), allShapes[i].getAllPoints()[j-1].getY()); path.cubicTo(allShapes[i].getAllPoints()[j].getX(), allShapes[i].getAllPoints()[j].getY(), allShapes[i].getAllPoints()[j+1].getX(), allShapes[i].getAllPoints()[j+1].getY(), allShapes[i].getAllPoints()[j+2].getX(), allShapes[i].getAllPoints()[j+2].getY()); painter.drawPath(path); } } } void Draw::wheelEvent(QWheelEvent *event)
{
const int degrees = event->delta() / 8; int steps = degrees / 15; double scaleFactor = 1.0; const qreal minFactor = 1.0; const qreal maxFactor = 10.0; if(steps > 0) { m_ScaleFactor.scaleX = (m_ScaleFactor.scaleX >= maxFactor) ? m_ScaleFactor.scaleX : (m_ScaleFactor.scaleX + scaleFactor); m_ScaleFactor.scaleY = (m_ScaleFactor.scaleY >= maxFactor) ? m_ScaleFactor.scaleY : (m_ScaleFactor.scaleY + scaleFactor); } else { m_ScaleFactor.scaleX = (m_ScaleFactor.scaleX <= minFactor) ? minFactor : (m_ScaleFactor.scaleX - scaleFactor); m_ScaleFactor.scaleY = (m_ScaleFactor.scaleY <= minFactor) ? minFactor : (m_ScaleFactor.scaleY - scaleFactor); }
}