Page 1 of 2 12 LastLast
Results 1 to 20 of 32

Thread: Zooming scene Rect(Qt bug?)

  1. #1
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Zooming scene Rect(Qt bug?)

    Hi guys,

    I have 2 problem connected with zooming the scene.
    First of all, I am using the code beneath to zoom the given rect, but it alwas zoom the center(at the begining, for the first 2 times).
    Qt Code:
    1. void MyCLass::vZoomSceneRectangle(QRectF _rectangle)
    2. {
    3. m_view->fitInView(_rectangle,Qt::KeepAspectRatio); // or Qt::KeepAspectRatioBy expanding
    4. m_view->ensureVisible(_rectangle);
    5. }
    To copy to clipboard, switch view to plain text mode 

    The second problem is connected with fixed position. I have created QLabel as view->viewport() children(to set fixed position). When I scale the view(scale(2.0,20)), for the first 4 times their position is ok, but when I zoom In for the 5 time they change their position. So i am deleting them and recreating everytime they I zoom the scene rect and their position is ok(even though there are some painting lags).
    But when I use fitInView(QRectF) method my QLabel position changes and I am back where my problems appeared.

    Any idea how to zoom the chosen rectangle(correctly); I am currenly reading selected rectangle from the scene and use fitInView(QRectF..).
    How to force my widgets to ignore zooming(I belive it should be a default action , when I created them as children of the view->viewport()).

    For any ideas thank YOU.

    Maverick
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Zooming scene Rect(Qt bug?)

    How did you initialize the scene? Did you set the range of coordinates for it?

  3. #3
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Zooming scene Rect(Qt bug?)

    I have implemented my own custom scene.
    Here is the initialization.
    Qt Code:
    1. m_scene = new GScene(this);
    2. m_scene->setSceneRect(-50,50,m_view->width(),m_view->height());
    3. m_scene->setBackgroundBrush(QBrush(Qt::gray));
    4. m_scene->setItemIndexMethod(QGraphicsScene::BspTreeIndex);
    To copy to clipboard, switch view to plain text mode 

    Maverick
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Zooming scene Rect(Qt bug?)

    And how do you call the zooming method? A minimal compilable example reproducing the problem would help...

  5. #5
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Zooming scene Rect(Qt bug?)

    I have a parent class which contain scene and view objects.
    When I choose a rectangle for zooming I emit a signal which is connected to parent slot.
    SIGNAL:
    Qt Code:
    1. emit vSignalZoomRectangle(m_zoomPolygonItem->boundingRect());
    2. //m_zoom PolygonItem is a QPolygonItem created in the scene coordinates(the rect for zooming)
    To copy to clipboard, switch view to plain text mode 
    SLOT:
    Qt Code:
    1. void MyClass::vZoomSceneRectangle(QRectF _rectangle)
    2. {
    3. m_view->fitInView(_rectangle,Qt::KeepAspectRatio);
    4. //m_view->ensureVisible(_rectangle);
    To copy to clipboard, switch view to plain text mode 

    the connection is ok, and the correct rectF is passed, but no matter the rect coordinates the first zooming in ans other zoom the scene center point.

    ?
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Zooming scene Rect(Qt bug?)

    What are the exact numbers of the scene size and the rect you pass to fitInView?

  7. #7
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Zooming scene Rect(Qt bug?)

    It depend because I have a rectangle moving on the scene, and when I press the left mouse button the rectangle boundingRect is being read and passed.
    I have checked again and the rectangle passed/received are the same and do change their position.

    Maverick
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Zooming scene Rect(Qt bug?)

    I'd like to see the numbers though... In my opinion, you create the scene with incorrect coordinates - you use the size of the view, but I suspect the view hasn't been shown earlier, thus it doesn't have its size calculated yet and you are receiving bogus values that later on cause your scene to be always centered in the view (which is a normal behaviour if the scene is smaller than the view). So please use qDebug() and inspect those values.

  9. #9
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Zooming scene Rect(Qt bug?)

    Here are Top left/right and bottomLeft/Right points of the rectangles printed by the code in the Slot:
    Qt Code:
    1. qDebug()<<(_rectangle.bottomLeft().rx())<<(_rectangle.bottomLeft().ry());
    2. qDebug()<<(_rectangle.bottomRight().rx())<<(_rectangle.bottomRight().ry());
    3. qDebug()<<(_rectangle.topLeft().rx())<<(_rectangle.topLeft().ry());
    4. qDebug()<<(_rectangle.topRight().rx())<<(_rectangle.topRight().ry());
    To copy to clipboard, switch view to plain text mode 

    1.

    -606 -21
    -356 -21
    -606 -171
    -356 -171

    2.
    340 -76
    590 -76
    340 -226
    590 -226

    3.
    -135 99
    115 99
    -135 -51
    115 -51

    1. 2. and 3. are different coordinates, but after fittingInvView(rect..) I get the same zoom effect.

    ??
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Zooming scene Rect(Qt bug?)

    And the scene size?

  11. #11
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Zooming scene Rect(Qt bug?)

    THe scene size is the same before zooming and after the action, but despite the given rectangle the scene looks the same after first zooming.

    Maverick
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Zooming scene Rect(Qt bug?)

    But what is the scene size? Could you show the exact figures - the scene size, the view size, the matrix of the view and the rectangle?

    Something like (relative to the view object):
    Qt Code:
    1. qDebug() << sceneRect() << size() << matrix() << _rectangle;
    To copy to clipboard, switch view to plain text mode 

  13. #13
    Join Date
    Jan 2006
    Location
    Norway
    Posts
    124
    Thanked 38 Times in 30 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Smile Re: Zooming scene Rect(Qt bug?)

    maverick_pol, please just send a compilable self-contained example, and the bug is likely to be revealed right away. It's hard to debug code that's translated to english.
    Bitto / Andreas Aardal Hanssen - andreas dot aardal dot hanssen at nokia
    Nokia Software Manager, Qt Development

  14. #14
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Zooming scene Rect(Qt bug?)

    Hi,

    I can't send you the code as I do not have permision to do so. I will send the (rectangle/size/etc) within 15 minutes.

    Here it is:

    The code I am using to print values:
    Qt Code:
    1. // the given _rectangle for zooming
    2. qDebug()<<(_rectangle.bottomLeft().rx())<<(_rectangle.bottomLeft().ry());
    3. qDebug()<<(_rectangle.bottomRight().rx())<<(_rectangle.bottomRight().ry());
    4. qDebug()<<(_rectangle.topLeft().rx())<<(_rectangle.topLeft().ry());
    5. qDebug()<<(_rectangle.topRight().rx())<<(_rectangle.topRight().ry());
    6. m_view->fitInView(_rectangle,Qt::KeepAspectRatio); // or Qt::KeepAspectRatioBy expanding
    7. // Scene rectangle
    8. _rectangle = m_view->sceneRect(); qDebug()<<(_rectangle.bottomLeft().rx())<<(_rectangle.bottomLeft().ry());
    9. qDebug()<<(_rectangle.bottomRight().rx())<<(_rectangle.bottomRight().ry());
    10. qDebug()<<(_rectangle.topLeft().rx())<<(_rectangle.topLeft().ry());
    11. qDebug()<<(_rectangle.topRight().rx())<<(_rectangle.topRight().ry());
    12. // scene rectangle(from view)
    13. _rectangle = m_scene->sceneRect(); qDebug()<<(_rectangle.bottomLeft().rx())<<(_rectangle.bottomLeft().ry());
    14. qDebug()<<(_rectangle.bottomRight().rx())<<(_rectangle.bottomRight().ry());
    15. qDebug()<<(_rectangle.topLeft().rx())<<(_rectangle.topLeft().ry());
    16. qDebug()<<(_rectangle.topRight().rx())<<(_rectangle.topRight().ry());
    17. // view size
    18. qDebug()<<m_view->size().height()<<m_view->size().width();
    19. //view matrix
    20. qDebug()<<m_view->matrix().m11()<<m_view->matrix().m12()<<m_view->matrix().m21()<<m_view->matrix().m22()<<m_view->matrix().det()<<m_view->matrix().dx()<<m_view->matrix().dy();
    To copy to clipboard, switch view to plain text mode 

    HEre is the result:

    -172 38
    78 38
    -172 -112
    78 -112
    -50 80
    50 80
    -50 50
    50 50
    -50 80
    50 80
    -50 50
    50 50
    660 1224
    4.34667 0 0 4.34667 18.8935 0 0

    QGraphicsScene::removeItem: item 01F45440's scene (00000000) is different from this scene (01AB88D8)

    -51.3037 67.408
    11.1963 67.408
    -51.3037 29.908
    11.1963 29.908
    -50 80
    50 80
    -50 50
    50 50
    -50 80
    50 80
    -50 50
    50 50
    660 1224
    17.3867 0 0 17.3867 302.296 0 0

    QGraphicsScene::removeItem: item 01E9E968's scene (00000000) is different from this scene (01AB88D8)

    -30.8857 57.2278
    -15.2607 57.2278
    -30.8857 47.8528
    -15.2607 47.8528
    -50 80
    50 80
    -50 50
    50 50
    -50 80
    50 80
    -50 50
    50 50
    660 1224
    67.84 0 0 67.84 4602.27 0 0

    QGraphicsScene::removeItem: item 01F78660's scene (00000000) is different from this scene (01AB88D8)

    -19.487 52.5501
    -15.5808 52.5501
    -19.487 50.2064
    -15.5808 50.2064
    -50 80
    50 80
    -50 50
    50 50
    -50 80
    50 80
    -50 50
    50 50
    660 1224
    271.36 0 0 271.36 73636.2 0 0

    I have used zoom In 4 times here and after the second Zoom IN my widgets(created with m_view->viewport() as the parent) moved left. I tried to recreate the widgets after zooming In (removing items and addint them once again) that's why I get the "removeITem" warning.

    Maverick
    Last edited by maverick_pol; 21st August 2007 at 13:01.
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  15. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Zooming scene Rect(Qt bug?)

    Looks like I was right from the very beginning - scene coordinates seem incorrect.

    BTW. You could have formatted the output better, you know...

  16. #16
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Zooming scene Rect(Qt bug?)

    Hi,

    I will format the INPUT correctly. Sound good that you were right, but I still do not know what is the problem. Could you explain it to me?
    When I use (scale() and fitInView() ) function the coordinates system changes, what kind of incorrectness you're seeing here?
    I really appreciate your help in this thread.

    Maverick
    Last edited by maverick_pol; 21st August 2007 at 13:45.
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  17. #17
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Zooming scene Rect(Qt bug?)

    Take a look at the coordinates of the zooming rect, the scene and the view during first two zooms. If you have trouble, take a piece of paper and draw the rectangles, taking a closer look at how they intersect each other. Only during the last two sets of coordinates the zooming rectangle is smaller than the scene. A nice thing to have would be to know the bounding rect of all the items in the scene as well...

    You should really try with a minimal compilable example as asked at the beginning... Or provide actual code - we won't steal it

  18. The following user says thank you to wysota for this useful post:

    maverick_pol (22nd August 2007)

  19. #18
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Zooming scene Rect(Qt bug?)

    Hi,

    Here is the piece of code I am using ( it's 100% what I have in my application(the part connected with gview framework).
    After choosing the Zoom in from the Context menu and once again clicking left mouse button the rectangle appears and can be moved with the cursor and resized while pressing the right mouse button.
    (There are 2 windows, the one with the gview is mine; other is not used)

    My "Panels"(in the fungc class) should be at the same place while zooming, but are moving.
    also in the begining(while zooming for first 2...4 times the center of the scene is zoomed not the rectangle).

    If you have any ideas I would appreciate your help.

    P.S. I have compiled/run this code using Qt 4.3.1 under win32

    Maverick
    Attached Files Attached Files
    Last edited by maverick_pol; 22nd August 2007 at 09:57.
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  20. #19
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Zooming scene Rect(Qt bug?)

    Hi guys,

    Any ideas what can be the problem?(wrong zooming rectangle and moving Panels(labels))

    Maverick
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  21. #20
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Looking for a solution for over a week...can't find it ;((GraphicsView)

    Hi guys,

    Excuse me for writing again about this problem, but the (my)last thread seems to die.
    I have a problem, which I can't solve for over a week, I attach the code and the link to the thread. If anyone could at least compile the code at look where the problem may be and give some ideas I would really appreciate it.

    THe problem.

    http://www.qtcentre.org/forum/f-qt-p...-bug-8625.html

    Thank you very much for your patience.

    Maverick
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

Similar Threads

  1. Creating a scene from piece of another scene
    By maverick_pol in forum Qt Programming
    Replies: 3
    Last Post: 23rd August 2007, 17:51
  2. Zooming scene
    By maverick_pol in forum Qt Programming
    Replies: 12
    Last Post: 2nd August 2007, 17:37
  3. How to use QGraphicsView and Scene right ...
    By Mike in forum Qt Programming
    Replies: 6
    Last Post: 22nd January 2007, 08:51

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.