Results 1 to 5 of 5

Thread: QGraphicsScene changes visible area when scenerect changes

  1. #1
    Join Date
    Feb 2015
    Posts
    12
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default QGraphicsScene changes visible area when scenerect changes

    Hi,
    when i click into the graphicsView with the following example a QGraphicsEllipseItem will be added.
    My problem is that the already existing QGraphicsEllipseItems seem to "mov"e each time when a new item is added.
    I want the visible are of the scene to be fixed.

    When i set the scene rect to a fixed rect, the items stay in position, but then the scene rect is not correct.
    I want the sceneRect to include all items and thad the visible area of the scene stays fixed when i add new items.

    Can anyone help?

    Qt Code:
    1. #include <QGraphicsScene>
    2. #include <QGraphicsView>
    3. #include <QApplication>
    4. #include <QGraphicsEllipseItem>
    5. #include <QMouseEvent>
    6. #include <QPointF>
    7.  
    8. class MyView : public QGraphicsView {
    9. public:
    10. void mousePressEvent(QMouseEvent *event) {
    11. QPointF pos = mapToScene(event->pos());
    12. scene()->addItem(new QGraphicsEllipseItem(pos.x()-5,pos.y()-5,10,10));
    13. }
    14. };
    15.  
    16. int main(int argc, char **argv) {
    17.  
    18. QApplication app(argc, argv);
    19.  
    20. MyView v;
    21. v.setScene(&scene);
    22. v.show();
    23.  
    24. return app.exec();
    25.  
    26. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsScene changes visible area when scenerect changes

    You could try to set the view's resize anchor to NoAnchor.

    Cheers,
    _

  3. #3
    Join Date
    Feb 2015
    Posts
    12
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsScene changes visible area when scenerect changes

    setting the resize anchor doesn't help. As far as is understand, the resize anchor is only relevent when the QGraphicsView is resized?

    When i add items, not the size of the QGraphicsView is changed, but the size of the sceneRect.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsScene changes visible area when scenerect changes

    Ah, too bad.
    Would have been a lucky guess

    Cheers,
    _

  5. #5
    Join Date
    Feb 2015
    Posts
    12
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsScene changes visible area when scenerect changes

    ok... i guess its not a big deal if you know how to do it. Any other ideas?

Similar Threads

  1. Replies: 10
    Last Post: 8th April 2015, 19:38
  2. QGraphicsscene.sceneRect on Windows platform
    By sanku3 in forum Qt Programming
    Replies: 0
    Last Post: 26th September 2011, 09:12
  3. QGraphicsScene's sceneRect() doesn't update
    By blooglet in forum Qt Programming
    Replies: 2
    Last Post: 17th February 2011, 10:11
  4. QTableView selected row not in visible area
    By mstegehu in forum Qt Programming
    Replies: 3
    Last Post: 22nd June 2010, 08:45
  5. QGraphicsScene: evolution of sceneRect
    By Pieter from Belgium in forum Qt Programming
    Replies: 2
    Last Post: 10th November 2006, 16:11

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.