Results 1 to 2 of 2

Thread: Date-time axis

  1. #1
    Join Date
    Oct 2015
    Posts
    10
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Date-time axis

    I inherit class from QwtScaleDraw to show date-time axis:

    Qt Code:
    1. class TimeScaleDraw: public QwtScaleDraw {
    2. public:
    3.  
    4. TimeScaleDraw(const QDateTime &base) : baseDateTime(base)
    5.  
    6. {
    7. setLabelRotation(0);
    8. setLabelAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
    9. setSpacing(20);
    10. }
    11. virtual QwtText label(double v) const
    12. {
    13. QDateTime dateTime;
    14. dateTime = dateTime.fromTime_t(v);
    15. return dateTime.toString("yyyy.MM.dd\nhh:mm:ss");
    16. }
    17. private:
    18. QDateTime baseDateTime;
    19. };
    To copy to clipboard, switch view to plain text mode 

    In main file I use it as:

    Qt Code:
    1. funPlot->setAxisScaleDraw(QwtPlot::xBottom, new TimeScaleDraw(QDateTime::currentDateTime()));
    To copy to clipboard, switch view to plain text mode 

    I want to see the current date-time by default when I run the app. Is it possible? Now it displays as 1970.01.00 00:00:00 with an appropriate scale.

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,309
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Date-time axis

    Quote Originally Posted by Cat View Post
    Now it displays as 1970.01.00 00:00:00 with an appropriate scale.
    Yes this is the null date ( 0 ms from Epoch ). I recommend to use the QwtDate classes - see http://qwt.sourceforge.net/class_qwt_date.html#details.

    Uwe

Similar Threads

  1. QCustomPlot using timestamp to set Date along one axis
    By bandito in forum Qt Programming
    Replies: 4
    Last Post: 5th March 2016, 19:32
  2. KDChart Date-time Axis howto?
    By galrub in forum Qt Programming
    Replies: 0
    Last Post: 15th October 2012, 12:36
  3. Date Scale for X-Axis
    By mishani99 in forum Qwt
    Replies: 3
    Last Post: 6th September 2011, 12:40
  4. Replies: 1
    Last Post: 2nd August 2011, 19:01
  5. Time/Date Axis
    By sigger in forum Qwt
    Replies: 12
    Last Post: 1st May 2011, 10:55

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.