Results 1 to 2 of 2

Thread: Using custom coordinates with QGraphicsScene

  1. #1
    Join Date
    Jun 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question Using custom coordinates with QGraphicsScene

    I am experimenting with a WYSIWYG editor that allows a user to draw shapes on a page and the Qt graphics scene support seems perfect for this. However, instead of working in pixels I want all my QGraphicsItem objects to work in tenths of a millimetre but I don't know how to achieve this.

    For example:

    Qt Code:
    1. // Create a scene that is the size if an A4 page (2100 = 21cm, 2970 = 29.7cm)
    2. QGraphicsScene* scene = new QGraphicsScene(0, 0, 2100, 2970);
    3. // Add a rectangle located 1cm across, 1cm down, 5cm wide and 2cm high
    4. QGraphicsItem* item = scene->addRect(100, 100, 500, 200);
    5. ...
    6. QGraphicsView* view = new QGraphicsView(scene);
    7. setCentralWidget(view);
    To copy to clipboard, switch view to plain text mode 

    Now, when I display the scene above I want the shapes to appear at correct size for the screen DPI. Is this simply a case of using QGraphicsView::scale or do I have to do something more complicated?

    Note that if I was using a custom QWidget instead then I would use QPainter::setWindow and QPainter::setViewport to create a custom mapping mode but I can't see how to do this using the graphics scene support.

    Any advice on WYSIWYG support with scenes is welcome.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Using custom coordinates with QGraphicsScene

    However, instead of working in pixels I want all my QGraphicsItem objects to work in tenths of a millimeter but I don't know how to achieve this.
    The QGraphicsView coordinate system is not pixel based, its logical.
    For convenience, a non transformed one unit corresponds to one pixel.
    But you can transform it to fit any unit you want.

    If you want to have the displayed units correspond with tenth of cm,you have to take the physical size of the screen pixel in account, which may differ between screens.
    If the displayed image does not need to have a real physical size, and only the correct unit ratio, then you have no problem.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Replies: 7
    Last Post: 21st March 2010, 03:11
  2. Replies: 4
    Last Post: 18th March 2010, 10:11
  3. Replies: 0
    Last Post: 24th November 2008, 08:52
  4. Working with coordinates (QGraphicsScene/view)
    By maverick_pol in forum Qt Programming
    Replies: 5
    Last Post: 27th March 2008, 08:35
  5. Retrieving mouseover coordinates of QGraphicsScene
    By forrestfsu in forum Qt Programming
    Replies: 2
    Last Post: 23rd October 2006, 18:36

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.