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. QGraphicsRectItem on QGraphicsView doesn't update while zooming the QGraphicsView
Qt 6.11 is out! See what's new in the release blog

QGraphicsRectItem on QGraphicsView doesn't update while zooming the QGraphicsView

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 2 Posters 1.0k Views 1 Watching
  • 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.
  • K Offline
    K Offline
    Kamilen_
    wrote on last edited by
    #1

    I would like to ask you for help with the problem. (Qt 4.8)

    In general, problem lies in QGraphicsView and QGraphicsRectItems in it. I've created simple application which allows you to add some pixels by clicking left mouse button. Everything works nice, except zooming which is done using mouse wheel events.

    The problem is in not updating QGraphicsRectItem objects which are already added to the QGraphicsScene .

    As you can see on the image below, i added one pixel and everything is shown properly.

    Ybd4C.png

    But when i will zoom out the picture, this happens:

    EvhaP.png

    Here is code which is responsible for adding rects to the scene:

    void CustomView::mousePressEvent( QMouseEvent *event )
    {
        if( m_Cursor == MOVE_CURSOR )
        {
            m_OriginX = event->x();
            m_OriginY = event->y();
            setCursor( Qt::ClosedHandCursor );
        }
        else
        {
            QPoint position = mapToScene( event->pos() ).toPoint();
            QGraphicsRectItem *pNewItem = new QGraphicsRectItem( position.x(), position.y(), 1, 1 );
            m_RectItemVector.push_back( pNewItem );
            m_pScene->addItem( pNewItem );
        }
    }
    

    And here is code which is responsible for zooming in/out:

    void CustomView::wheelEvent( QWheelEvent *event )
    {
        QPointF pointWheel = mapToScene( event->pos() );
        if( event->delta() > 0 )
        {
            scale( SCALE_FACTOR, SCALE_FACTOR );
        }
        else
        {
            scale( 1/SCALE_FACTOR, 1/SCALE_FACTOR );
        }
        centerOn( pointWheel.x(), pointWheel.y() );
    }
    

    Maybe some of you had this issue and found some workaround, or maybe i'm doing something wrong? I would be grateful for any tips and thanks in advance!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      I am not sure I understand your issue here.

      Would it be possible for you to draw the outcome you are expecting with the zoom ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • K Offline
        K Offline
        Kamilen_
        wrote on last edited by Kamilen_
        #3

        Hello @SGaist

        Basically i wanted to create application which will allow to "mark" chosen pixel by clicking on one with mouse button. On the first screenshot chosen rect is drawn properly, but when image is zoomed out, on the second screenshot rect is slightly "moved" to the left which schould not happen.

        This phenomenon occurs only with few scale factors. Today i found also the origin of the issue. When scaling, image is being cropped a bit on the right side, so the last column of pixels is cut in half or sometimes more.

        Although today i found that this was a bug in Qt which was reported, i'm still looking for some kind of workaround.

        Link to the issue:
        https://bugreports.qt.io/browse/QTBUG-60782

        Here is how the result should looks like (compared to the second screenshot):
        bcc03fbb-0fff-40cc-9266-42c3f51291c5.png

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Can you check with a more recent version of Qt if you still have that issue ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • K Offline
            K Offline
            Kamilen_
            wrote on last edited by
            #5

            I was checking it with Qt 5 and it seems that this issue is no longer exists. My problem lies in that i need to find some workaround on Qt 4.8.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Then you will have to do some code comparison between the Qt 5 version were the issue is fixed and what you have with Qt 4.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              2
              • K Offline
                K Offline
                Kamilen_
                wrote on last edited by
                #7

                Thanks, nice idea. I will give it a try.

                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