Results 1 to 6 of 6

Thread: Graphics View: Drawing Items that don't scale

  1. #1
    Join Date
    May 2009
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Graphics View: Drawing Items that don't scale

    Hi everyone,

    I need to find a way to draw Items such that they always get drawn in the same size, even when I zoom in on them.
    For example, I want to be able to draw a Point like this:

    drawMyPoint(position, thickness)

    where 'position' should be in scene coordinates, whereas 'thickness' should be in pixels. The point shall be painted in the same size, independent from the zoom level.

    The motivation for this is that I have to mark road crossings on a map. Until now I use 'drawPoint', but it only draws it as one coloured pixel.

    Thanks for your help

    Daniel

  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: Graphics View: Drawing Items that don't scale

    Read about QGraphicsItem::ItemIgnoresTransformations.
    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
    May 2009
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Graphics View: Drawing Items that don't scale

    Quote Originally Posted by wysota View Post
    Read about QGraphicsItem::ItemIgnoresTransformations.
    I did, but as I understand I would still have to initially provide the size of the Item in scene coordinates, wouldn't I?

  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: Graphics View: Drawing Items that don't scale

    Yes, each item has to have a size... But this is easy if you do know the scene size.
    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
    May 2009
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Graphics View: Drawing Items that don't scale

    Quote Originally Posted by wysota View Post
    Yes, each item has to have a size... But this is easy if you do know the scene size.
    I tried to do this with EllipseItems, but it didn't work well, and it is quite complicated. Actually I don't want the items to have a size. They should be just points without width and height. But I would like to be able to tell Qt to use a thicker pen.
    Ultimately, Graphics View transforms the scene coordinates to view coordinates and draws a pixel somewhere on the screen. There should be no need to use a more complicated Item just to get a thicker point.

  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: Graphics View: Drawing Items that don't scale

    Quote Originally Posted by Disperato View Post
    Actually I don't want the items to have a size.
    Sure you do.

    They should be just points without width and height.
    A point is a mathematical concept, you can't visualize a point. What you want is something that occupies a pixel on the screen.
    But I would like to be able to tell Qt to use a thicker pen.
    So you want it to occupy a few pixels on the screen...

    Ultimately, Graphics View transforms the scene coordinates to view coordinates and draws a pixel somewhere on the screen. There should be no need to use a more complicated Item just to get a thicker point.
    The whole point of graphics view is that it operates in scene coordinates instead of screen coordinates. If you don't want scene coordinates, don't use graphics view or keep the scene resolution synchronized with the view resolution (which means "no zooming"). You can't eat a cake and have a cake.

    All you need to do is to calculate how many units in world (scene) coordinates a single pixel on the screen occupies. This is an easy calculation if you know the size unit of the scene and the resolution of the view. You should know the former and Qt knows the latter - just use both pieces of information and you're done.
    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.


Similar Threads

  1. Graphics View and the Pixmap
    By spawn9997 in forum Qt Programming
    Replies: 2
    Last Post: 26th June 2009, 22:12
  2. Replies: 6
    Last Post: 8th June 2009, 21:44
  3. Replies: 5
    Last Post: 17th February 2009, 04:35
  4. Replies: 4
    Last Post: 5th August 2008, 19:55
  5. Cann't move movable items on custom graphics view
    By wojtekw in forum Qt Programming
    Replies: 2
    Last Post: 3rd March 2008, 21:30

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.