Results 1 to 3 of 3

Thread: Problem with QGraphicsView adjusting it's view

  1. #1
    Join Date
    Jan 2010
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Problem with QGraphicsView adjusting it's view

    Hey,

    I've just started looking into Qt 4.6.1 (and I'm liking it ) and I want to create a little vector graphics based program as an exercise.

    I've subclassed QGraphicsScene so when you press left mouse button, it simply adds a QGraphicsPolygonItem. When such an item is added to the scene, the associated QGraphicsView automatically adjusts its view, so that all the items are centered. This may be a neat feature in some cases, but in this case it's just confusing, if the view always adjust itself when adding new items.

    I've tried looking in the documentation and on the Diagram Scene example that comes with Qt Creator, but I can't find out how to prevent the QGraphicsView from automatically adjusting its view.

    Any help would be appreciated.

    Btw. I used Qt designer to create the form with QGraphicsView if that makes a difference.

  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: Problem with QGraphicsView adjusting it's view

    When you don't explicitly set the size of the scene, it grows according to range of coordinates occupied by its items. At the same time if the view is larger than the scene then by default the scene is centred in the view. Toghether this causes the effect you are experiencing. If you want to avoid it, it's best if you set the geometry of the scene before adding items to it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    pstudio (31st January 2010)

  4. #3
    Join Date
    Jan 2010
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with QGraphicsView adjusting it's view

    Thanks, that solved the problem. I just knew it would be something simple like that

Similar Threads

  1. Fit In View a loaded image to QGraphicsView
    By sincnarf in forum Qt Programming
    Replies: 4
    Last Post: 11th September 2014, 08:23
  2. [QGraphicsView] Auto adjusting QGraphicsScene
    By Macok in forum Qt Programming
    Replies: 1
    Last Post: 21st March 2009, 22:31
  3. Adjusting contrast and brighness of QGraphicsView
    By olidem in forum Qt Programming
    Replies: 6
    Last Post: 18th March 2009, 09:23
  4. Adjusting window to QGraphicsView contents
    By IrYoKu in forum Qt Programming
    Replies: 2
    Last Post: 27th August 2007, 12:10
  5. Using QGraphicsView with model/view programming
    By JLP in forum Qt Programming
    Replies: 3
    Last Post: 29th January 2007, 11:04

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.