Results 1 to 4 of 4

Thread: QGraphicsView - resize items on graphicsview resize -> calculate new positions

  1. #1
    Join Date
    Nov 2011
    Posts
    26
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows

    Default QGraphicsView - resize items on graphicsview resize -> calculate new positions

    Hey Guys,

    I am using a GraphicsView with a GraphicsScene which i added a PixmapItem....
    The QGraphicsPixmapItem is treated as my background item on Z-value "0" on Z-value "1" i have several other pixmapItems.

    My Problem:
    When i resize the whole program the QGraphicsView also resizes and so the Background item should be resized (what works fine) - it is just a *.scaled() Pixmap where scaled() gets the current size of the GraphicsView.
    Now i have to reposition the items on Z-value "1" to match the "same" position as before on the underlaying pixmap

    My current Solution:
    My current solution is not correct becauze the repositioning does "not work" - it's not exact .. (for the Background PixmapItem i used Qt::KeepAspectRatio)
    I saved the original size of the background Pixmap and the position of each Item for that "base size"
    On resizing i calculate the new x and y coordinates by referring to the old width/height of the Background Pixmap

    This means:
    NewWidth/oldWidth * oldX-Coordinate = NewX-Coordinate
    NewHeight/oldHeight * oldY-Coordinate = NewY-Coordinate

    Anyway .. it's "kinda" working but not exact (i thought it would work better that way ^^)

    Anybody an idea how it is possible to calculate that more precisely?? - Would be really lovely
    Thanks =)

  2. The following user says thank you to shock for this useful post:


  3. #2
    Join Date
    Nov 2011
    Posts
    26
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView - resize items on graphicsview resize -> calculate new positions

    Has nobody any idea? There must be a smart way to solve this i think!?

  4. The following user says thank you to shock for this useful post:


  5. #3
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsView - resize items on graphicsview resize -> calculate new positions

    I'm just wondering, why you have to change position of the items in the scene?

    Wouldn't it be simpler to add all the items to the scene in the places you want them, and then on every resize call QGraphicsView::fitInView() ?

    This will make sure that everything is scalled as required and positioned correctly (that's assuming that you're not bothered that everything will get smaller/bigger as you change window size).

    Unless I've misunderstood what you want to achieve.

  6. The following 2 users say thank you to Spitfire for this useful post:

    shock (11th December 2011)

  7. #4
    Join Date
    Nov 2011
    Posts
    26
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView - resize items on graphicsview resize -> calculate new positions

    Hmm ... seems it was really that simple... Thanks man

  8. The following user says thank you to shock for this useful post:


Similar Threads

  1. Replies: 7
    Last Post: 1st December 2011, 16:24
  2. Replies: 1
    Last Post: 9th May 2011, 20:45
  3. How to resize the Items in FormLayout
    By sudhansu in forum Qt Programming
    Replies: 12
    Last Post: 4th December 2009, 06:34
  4. Replies: 2
    Last Post: 22nd January 2008, 16:10
  5. getting QGraphicsView to resize
    By MrGarbage in forum Qt Programming
    Replies: 1
    Last Post: 22nd January 2008, 03:49

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.