Results 1 to 2 of 2

Thread: How to map datitmes to qgraphicsscene

  1. #1
    Join Date
    Jul 2010
    Qt products

    Default How to map datitmes to qgraphicsscene

    I'm facing for the first time this kind of problem: my input data are datetime events, and I have to draw they into a qgraphicsscene. In the diagramscene demo application I found all the basics to start drawing, but I didn't realize how to convert datetime events to x and y coordinates into scene.

    If I have a qgraphicsscene that is 3000x3000 pixels wide, and a datetime interval that is three day long with some events inside, how could i translate this temporal coordinates to x and y ?

  2. #2
    Join Date
    Aug 2008
    Thanked 6 Times in 6 Posts
    Qt products
    Unix/X11 Windows

    Default Re: How to map datitmes to qgraphicsscene

    Err, well, how about if you convert the the datetime to seconds and then use the seconds as a coordinate value?
    Something like this:
    Qt Code:
    1. QDateTime intervalStart = /* some start date time value */;
    2. QDateTime intervalEnd = intervalStart.addDays( 3 );
    3. int maxTimeLength = intervalStart.secsTo( intervalEnd );
    4. int maxPixelLength = 3000;
    5. double pixelPerSecond = (double)maxPixelLength / maxTimeLength;
    6. // then convert each event's time to x-coordinate as pixels
    7. someEventCoordinateX = intervalStart.secsTo( someEventDateTime ) * pixelPerSecond;
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to joyer83 for this useful post:

    corrado1972 (31st May 2011)

Similar Threads

  1. Help with QGraphicsScene
    By justin123 in forum Newbie
    Replies: 2
    Last Post: 3rd June 2010, 00:48
  2. Bug in QGraphicsScene?
    By tbcpp in forum Qt Programming
    Replies: 2
    Last Post: 12th June 2009, 14:23
  3. in QGraphicsScene matrix of other QGraphicsScene
    By Noxxik in forum Qt Programming
    Replies: 5
    Last Post: 15th February 2009, 17:27
  4. QGraphicsSCene
    By bhogasena in forum Qt Programming
    Replies: 1
    Last Post: 29th January 2009, 23:58
  5. Help on QGraphicsScene
    By Sandip in forum Qt Programming
    Replies: 1
    Last Post: 11th April 2008, 14:20

Tags for this Thread


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.