Results 1 to 7 of 7

Thread: QGraphics scene position

  1. #1
    Join Date
    Oct 2009
    Location
    Rio de Janeiro - Brazil
    Posts
    19
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default QGraphics scene position

    Hi people,

    I'd like to set the scene itens atleast 10 points from the top and left GraphicsView border.
    But I couldn't until now.

    Selection_022.png

    A piece of my PyQt code:
    Qt Code:
    1. (...)
    2. picture = "ui/snap/" + gamepicture
    3. if not os.path.isfile(picture):
    4. picture = "ui/pixmaps/nopic.png"
    5. if gamestatus:
    6. color = QtGui.QColor(0, 0, 0, 0)
    7. pix = QtGui.QPixmap(QtCore.QSize(238, 174))
    8. pix.fill(color)
    9. rect = QtCore.QRectF(0.0, 0.0, 238, 174)
    10. painter = QtGui.QPainter()
    11. painter.begin(pix)
    12. painter.setRenderHints(QtGui.QPainter.Antialiasing, True)
    13. path = QtGui.QPainterPath()
    14. path.addRoundedRect(rect, 10.0, 10.0)
    15. painter.drawPath(path)
    16. brush = QtGui.QBrush()
    17. brush.setTexture(QtGui.QPixmap(picture))
    18. painter.fillPath(path, brush)
    19. painter.end()
    20. pixItem = GameItem(gameid, pix, None, self.scene)
    21. pixItem.setPos((260 * col), lin)
    22. col += 1
    23. if col >= 6:
    24. lin += 220
    25. col = 0
    26. self.graphicsView.setScene(self.scene)
    27. self.graphicsView.setAlignment(QtCore.Qt.AlignLeft)
    28. (...)
    To copy to clipboard, switch view to plain text mode 

    Some tip?

    BR,

    Junix
    Last edited by junix; 13th April 2012 at 22:15. Reason: text organization

  2. #2
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QGraphics scene position

    That's probably because You don't take into account initial shift/offset of items from the border.
    I don't see initial values of variables but try something like this:

    Qt Code:
    1. pixItem.setPos((260 * col) + offsetX, lin + offsetY)
    To copy to clipboard, switch view to plain text mode 
    In the near future - corporate networks reach out to the stars. Electrons and light flow throughout the universe.
    The advance of computerization however, has not yet wiped out nations and ethnic groups.

  3. #3
    Join Date
    Oct 2009
    Location
    Rio de Janeiro - Brazil
    Posts
    19
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphics scene position

    Sorry, but it doesn't work.
    I've set the offset, but nothing change.

  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: QGraphics scene position

    Did you set the scene size? And do you mean the initial position or that you always want to have 10 pixels of margin between the widget and its contents?
    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
    Oct 2009
    Location
    Rio de Janeiro - Brazil
    Posts
    19
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphics scene position

    I've set the size: rect = QtCore.QRectF(0.0, 0.0, 238, 174)
    I have rounded corners: path.addRoundedRect(rect, 10.0, 10.0)

    I'd like to separate from the borders (space of 10 pixels).

  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: QGraphics scene position

    Ok, that's easy then. You need to use setViewportMargins() to make a margin between the widget and its viewport. It is possible QGraphicsView will try to override that in which case you'll need to override resizeEvent() and force those margins again on each resize. You will probably also want to change the frame of the viewport and possibly the frame of the scroll area itself.
    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. The following user says thank you to wysota for this useful post:

    junix (17th April 2012)

  8. #7
    Join Date
    Oct 2009
    Location
    Rio de Janeiro - Brazil
    Posts
    19
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphics scene position

    Perfect!

    Thank you.

    BR,

    Junix

Similar Threads

  1. Saving QGraphics Scene items
    By chaltier in forum Qt Programming
    Replies: 1
    Last Post: 3rd April 2012, 06:35
  2. Infinite (circular) QGraphics Scene
    By maitai in forum Qt Programming
    Replies: 10
    Last Post: 27th March 2011, 15:23
  3. QGraphics View Scene performance with polylines
    By iampowerslave in forum Qt Programming
    Replies: 0
    Last Post: 15th November 2010, 17:03
  4. MouseEvent in QGraphics Scene?
    By fanatos in forum Newbie
    Replies: 1
    Last Post: 9th September 2010, 17:39
  5. Cursor Position in scene
    By rogerholmes in forum Newbie
    Replies: 2
    Last Post: 12th March 2010, 15:31

Tags for this Thread

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.