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

Thread: Zooming scene Rect(Qt bug?)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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
    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

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

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

    Quote Originally Posted by maverick_pol View Post
    Excuse me for writing again about this problem, but the (my)last thread seems to die.
    Please don't start more than one thread on the same topic.

  14. The following user says thank you to jacek for this useful post:

    maverick_pol (24th August 2007)

  15. #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?)

    Sorry. I should rather try to "refresh" the thread.

    using "update()", does not give any improvement.
    Still looking for a solution. Ideas appreciated.

    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

  16. #15
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Zooming scene Rect(Qt bug?)

    Alright, I gave it a try but I'm sorry to say I soon gave up. A couple of clear errors:
    • a QGraphicsView object allocated on the stack is being deleted => crash
    • a QGraphicsView* is incorrectly casted as GView*, an actual GView is never created (once you add a member to GView and try to call it => crash)

    Other comments:
    I'm not saying any of these particular issues would cause the misfunctionality, but things like public variables and first setting QGraphicsScene::NoIndex in GScene constructor but then switching it immediately to QGraphicsScene::BspTreeIndex in FundGC just make it hard to follow what is being modified and where, and who controls what. Sorry, but the attached code is a bit too "bloated" for an outsider to quickly see what's going on.
    J-P Nurmi

  17. #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?)

    Ok, I will correct the mistaked right away.
    But do you have ideas why the zooming is wrong ?

    I understand that the code may not be as clear and high quality as at your level of coding, but I would like you, if it is not a problem, to look at 2 methods.

    fundgc.cpp ->FundGC::vZoomSceneRectangle(QRectF _rectangle);
    scene.cpp ->GScene::mousePressEvent ( QGraphicsSceneMouseEvent * mouseEvent );

    mousePressEvent passes the rectangle for zooming(
    Qt Code:
    1. emit vSignalZoomRectangle(m_zoomPolygonItem->boundingRect());
    To copy to clipboard, switch view to plain text mode 
    and the vZoom... zooms the rectangle. There is an error in the this methods or scene settings, which I can't find on my own.

    A -> base class
    B: public A

    dynamic_cast<B*>(A*) <- why this casting will not work? ( or static)

    I really appreciate your help and ideas.

    Maverick
    Last edited by maverick_pol; 24th August 2007 at 13:24.
    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

  18. #17
    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 have na idea where the problem lays(I suppose that wysote suggested it at the beginning in the first place, but didn't understand the idea). I belive the problem is connected with scene/view sizes.
    Here is the information about the view/scene sizes after construction and their sizes while doing the first zooming.

    Just after construction:
    Qt Code:
    1. qDebug()<<m_view->size().height()<<m_view->size().width();
    2. m_scene->setSceneRect(-50,50,m_view->width(),m_view->height());
    3. qDebug()<<m_scene->sceneRect().height()<<m_scene->sceneRect().width();
    To copy to clipboard, switch view to plain text mode 

    100 30
    100 30
    Before doing the first zooming :
    Qt Code:
    1. qDebug()<<m_view->size().height()<<m_view->size().width();
    2. qDebug()<<m_scene->sceneRect().height()<<m_scene->sceneRect().width();
    To copy to clipboard, switch view to plain text mode 

    660 1224
    100 30
    I would like to have the same coordinate system in the scene and the view. It looks like because of the scene/view size different the zooming is incorrect. Am I right?

    Because the first zooming rectangle(from my example zooming) has coordinates:
    -285 157
    215 157
    -285 -143
    215 -143
    and it's bigger than the scene, so I zoom the whole(the center).
    Ok...I belive this is the problem, but yet do not know how to fix it ?

    Any help appreciated.


    Maverick
    Last edited by maverick_pol; 25th August 2007 at 13:04.
    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

  19. #18
    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?)

    You are creating the scene before the view is first shown. It such situation you can't rely on the view size, thus such small size of the scene. This probably causes the problem - when you zoom enough, the scene will become bigger than the view (after the transformation), causing the zoom to really happen (with wrong parameters, of course).

    And that's what I was saying from the very beginning...

    BTW. Try doing:
    Qt Code:
    1. qDebug() << QSize(20, 20);
    To copy to clipboard, switch view to plain text mode 
    You don't have to break QSize (and other value based Qt classes) to lowlevel bits like width and height when passing them to qDebug - they'll be printed correctly without that. It simplifies debugging structures very much, you should try it.

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

    maverick_pol (28th August 2007)

  21. #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,

    Yes I do agree that your hints were correct:
    And that's what I was saying from the very beginning...
    I see that in my code I have to methods, and firstly I set the scene rect(using mview attributes) and then when I show the view(at my window is maximized view size changes, but not the scene coordinate system).

    Thank you for the idea:
    You don't have to break QSize (and other value based Qt classes) to lowlevel bits like width and height when passing them to qDebug - they'll be printed correctly without that. It simplifies debugging structures very much, you should try it.
    I will test it righ away and try to fix the zooming problem.

    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

  22. #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 Re: Zooming scene Rect(Qt bug?)

    Ok the problem is clear, but can't really get what I want.
    During construction view size is (30,100). Then after maximixing (660,1224).
    I can't set m-scene rectangle as (30,100) because after maximizing the coordinates are wrong. I tried setting the scene rectangle to (660,1224), but than the scene is much bigger than the viewport. My scene should always be the same size as the viewport, have the same coordinates system.

    Howto achieve this? I am trying to fix it, but still when zooming is Ok the scene is to big and I have to center is in the view.

    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.