Results 1 to 15 of 15

Thread: QGraphicsView keep shifting origin whenever i add an object in..

  1. #1
    Join Date
    Mar 2012
    Posts
    14
    Thanks
    1
    Platforms
    Windows

    Default QGraphicsView keep shifting origin whenever i add an object in..

    Need some help here..

    Why is it that whenever an object is added to my scene (base on mouse click x-y coordinates), the origin would shift to another part of the view..

    Once i drag the item around till the horizontal and verticle scroll bars are enabled..I would then able to add objects in without the view shifting around..

    Does anyone know what causes this?

    Thanks

  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: QGraphicsView keep shifting origin whenever i add an object in..

    You didn't explicitly set the scene size thus the scene grows as you are adding items to it and since the scene is centered in the view by default, the scene seems to move in the view.
    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. #3
    Join Date
    Mar 2012
    Posts
    14
    Thanks
    1
    Platforms
    Windows

    Default Re: QGraphicsView keep shifting origin whenever i add an object in..

    Hi thanks for the reply..

    If i explicitly set the scene size using setSceneRect, how do i re-enable the dynamically created verticle/horizontal scroll bars when an object go out of view?

    thank you..

  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: QGraphicsView keep shifting origin whenever i add an object in..

    If you set the scene size to be larger than the view, scrollbars will be there. You can also zoom in on the scene to make them appear.
    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.


  5. #5
    Join Date
    Mar 2012
    Posts
    14
    Thanks
    1
    Platforms
    Windows

    Default Re: QGraphicsView keep shifting origin whenever i add an object in..

    but i only wan the scroll bars to be there when the scene size gets bigger than the view..

    so when the scene is small, no scroll bar, when scene gets big, scroll bars appear..

    how do i achieve that?

    because right now if i explicitly set the scene size and if i bring a huge image in, a part of it would be cut off (no scroll bar appears for me to navigate the cut-ed part)

    thanks again..

  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: QGraphicsView keep shifting origin whenever i add an object in..

    Quote Originally Posted by chaltier View Post
    but i only wan the scroll bars to be there when the scene size gets bigger than the view..

    so when the scene is small, no scroll bar, when scene gets big, scroll bars appear..

    how do i achieve that?
    That's what you get by default. I don't see what the problem is then. Maybe it's enough if you change the alignment of the view to be top-left? Then your items won't seem to move however the scene will look strange in the beginning.
    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.


  7. #7
    Join Date
    Mar 2012
    Posts
    14
    Thanks
    1
    Platforms
    Windows

    Default Re: QGraphicsView keep shifting origin whenever i add an object in..

    The default is acting really weird..

    after i align the view to left..

    the first object, no matter where i place it on the screen, will automatically be placed at the extreme left of the screen..

    i wan the view to remain where it is and not move.. T_T

    thanks.

  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: QGraphicsView keep shifting origin whenever i add an object in..

    Then set scene boundaries. You can't eat the cake and have the cake. Either the scene adjusts to contents or not, you can't have both at the same time. Since your initial scene has no size, wherever you place the item, the scene will adjust its boundaries to this single item. Since the scene has to be aligned to something your item will be placed to respect that alignment.
    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.


  9. #9
    Join Date
    Apr 2012
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsView keep shifting origin whenever i add an object in..

    Hi guys, I am new to Qt and trying to build a desktop app. I have similar problem here and not sure what I did wrongly. I always have to manually force the scrollbar to come out. I took a video, hope it can better help explain my situation.


  10. #10
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QGraphicsView keep shifting origin whenever i add an object in..

    Video does not work here: "This video is private"

  11. #11
    Join Date
    Apr 2012
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsView keep shifting origin whenever i add an object in..

    I am so sorry, first time posting on youtube. Can the video be viewed now?

  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: QGraphicsView keep shifting origin whenever i add an object in..

    Set the scene size as I already advised in this thread.
    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.


  13. #13
    Join Date
    Apr 2012
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsView keep shifting origin whenever i add an object in..

    Is there any particular things i should base the scene size on?

  14. #14
    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: QGraphicsView keep shifting origin whenever i add an object in..

    The scene is your world. If you don't know the size of your world, nobody else will either.
    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.


  15. #15
    Join Date
    Apr 2012
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsView keep shifting origin whenever i add an object in..

    I've set the scene size..

    now when my scene gets bigger than the view, how do i get the scroll bars to appear?

Similar Threads

  1. Drag and Drop an Object Between Two View(QGraphicsView)
    By alizadeh91 in forum Qt Programming
    Replies: 1
    Last Post: 29th February 2012, 10:26
  2. Bitwise shifting and ORing HexaDecimal Value
    By nagabathula in forum Qt Programming
    Replies: 14
    Last Post: 19th November 2010, 07:22
  3. Shifting a QImage up by 1 pixel row
    By MSUdom5 in forum Qt Programming
    Replies: 2
    Last Post: 7th May 2010, 10:25
  4. Replies: 1
    Last Post: 2nd March 2009, 19:32
  5. Byte shifting in C
    By tntcoda in forum General Programming
    Replies: 3
    Last Post: 14th November 2008, 22:40

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.