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. QGraphicsView Scale / Zoom Issue & QGraphicsRectItem paint failed to called
Qt 6.11 is out! See what's new in the release blog

QGraphicsView Scale / Zoom Issue & QGraphicsRectItem paint failed to called

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 532 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.
  • S Offline
    S Offline
    SandyMedical
    wrote on last edited by SandyMedical
    #1

    My work Environment :Qt 5.8 MSVC2015 64bit, QT GraphicsView, QGraphicsRectItem, Windows 7 64 bit.

    Issues : When I zoom in & zoom out on GraphicsView, I call GraphicsView scale method. But When I add QGraphicsRectItem to scene it failed to call its paint method.

    my class hierarchy :

    class GraphicsView : public QGraphicsView
    class mySquare : public QObject, public QGraphicsRectItem
    class Scene : public QGraphicsScene
    

    Code :

    //////*****Draw Rect in QGraphicsRectItem *****////////////

    void mySquare::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    {
          QRectF rect(0,0,_width,_height);
          painter->drawRect(rect);
    }
    
    void GraphicsView::wheelEvent(QWheelEvent * event)
    {
      int angle = event->angleDelta().y(); // angle will tell you zoom in or out.
      double scaleFactor = 1.15; //How fast we zoom
      setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
      if (angle > 0)
      {
          qDebug()<<"Zoom in";
          scale(scaleFactor, scaleFactor);
      }
      else
      {
          qDebug()<<"Zoom out";
          scale(1.0 / scaleFactor, 1.0 / scaleFactor);
      }
          mySquare  _square = new mySquare(0,blankImage);
         _square->setPos(QPointF(0, 0));
    //Bug!!! Why after scale function call, _square failed to draw rect in paint method.
          _scene->addItem(_square);        //add square to scene. 
          _square->update(); 
    }
    

    my git code
    I spend days & hours but still not able to find out why it QGraphicsRectItem failed to print, when scale method get called. Any suggestion is highly appreciated ?

    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