Results 1 to 5 of 5

Thread: QGraphicsView::centerOn not working propery in 4.6

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default Re: QGraphicsView::centerOn not working propery in 4.6

    Nope, default is center according to the api. The alignment also isn't associated with QGraphicsScene, it's with QGraphicsView:

    "For example, if the alignment is Qt::AlignCenter, which is default, the scene will be centered in the view", but this apparently only holds true "If the whole scene is visible in the view", which it is not when the offset lines are drawn.

    If you look at the code with the commented section... I draw a picture (QImage) and I display two lines that show x and y offsets associated with the picture. If I don't draw those lines centerOn works fine. Otherwise the picture gets crammed in the top left corner. I'll try specifically setting the alignment to center, even though both the 4.5 and 4.6 state the default is Qt::AlignCenter and I'm using default. I'll try it when I get home but I can't imagine this being the problem.

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

    Default Re: QGraphicsView::centerOn not working propery in 4.6

    Quote Originally Posted by deca5423 View Post
    The alignment also isn't associated with QGraphicsScene, it's with QGraphicsView:
    I never said it was associated with the scene.

    If you look at the code with the commented section... I draw a picture (QImage) and I display two lines that show x and y offsets associated with the picture. If I don't draw those lines centerOn works fine. Otherwise the picture gets crammed in the top left corner. I'll try specifically setting the alignment to center, even though both the 4.5 and 4.6 state the default is Qt::AlignCenter and I'm using default. I'll try it when I get home but I can't imagine this being the problem.
    Could you provide a minimal compilable example reproducing the problem?
    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
    Jan 2010
    Posts
    11
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsView::centerOn not working propery in 4.6

    I too was having some problems with QGraphicsView::centerOn... so I tried using QGraphicsView::fitInView. This turned out to work really great for my needs. Although, to use it you have specify the exact rectangle that you'd like to see in the View (or the QGraphicsItem), so if you want to see more than just the QGraphicsItem then you need to make sure the rectangle you specify is larger than that item.

    Another thing you could do, if your graphical item is always the same size, is to use fitInView to set the View on the graphical item, then use scale to zoom out some amount.

    Lastly, if you don't want to change the scale of your view, then don't use fitInView, since it will adjust the transformation matrix (and zoom in/out accordingly).

    Good Luck!

Similar Threads

  1. beginInsertRows seems not to be working
    By ugurkoltuk in forum Qt Programming
    Replies: 3
    Last Post: 6th January 2010, 14:21
  2. working with shapefiles in Qwt
    By swamyonline in forum Qwt
    Replies: 2
    Last Post: 17th April 2009, 12:08
  3. F1 and WinHelp working with Qt
    By chrisdsimpson in forum Newbie
    Replies: 2
    Last Post: 18th April 2008, 19:08
  4. Propery capable QGraphicsTextItem
    By Gopala Krishna in forum Qt Programming
    Replies: 4
    Last Post: 16th March 2007, 18:26
  5. Mac OS X UI not working
    By hvengel in forum Qt Programming
    Replies: 3
    Last Post: 1st April 2006, 01:02

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
  •  
Qt is a trademark of The Qt Company.