Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. zoom qwidget
Qt 6.11 is out! See what's new in the release blog

zoom qwidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 923 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rest
    wrote on last edited by
    #1

    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);
        }
    

    }

    1 Reply Last reply
    0
    • P Offline
      P Offline
      patrik08
      wrote on last edited by
      #2

      Is This a QAbstractScrollArea or QGraphicsScene .. or simply QWidget?

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rest
        wrote on last edited by
        #3

        it is a simply qwidget where i draw some shapes, and i i want the to zoom on the mouse position. the problem is make a lot of stuff on paintevent.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved