Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QDateTime as float for QChart?
Forum Updated to NodeBB v4.3 + New Features

QDateTime as float for QChart?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nekkceb
    wrote on last edited by
    #1

    I dont find an easy conversion of a QDateTime to a float (e.g. qfloat). What I have in mind is the spreadsheet-like format, where integer part is days since X (I believe MSExcel uses jan 1 1900, other flavors may be different) and float part is fraction of the day. I find that format very convenient. My goal is to use QChart with the axes being either QValueAxis or QDateTimeAxis, particularly for the horizontal axis (asisX()). In the current implementation, the min() and setMin() methods use QDateTime for QDateTimeAxis and qreal for QValueAxis. I would like an overloaded set of methods so I could use qreal values for both. Any thoughts??

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      You can use "secTo":http://qt-project.org/doc/qt-5/qdatetime.html#secsTo to compute seconds as integer and divide by 86400.0 to obtain a float/double. Checkout if you can use Jan 1, 1900.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nekkceb
        wrote on last edited by
        #3

        Thanks for response, I have been using that. I am developing a plotting widget that is general enough so that in code, I will not necessarily know if the axisX is QValue or QDateTime. So, right now I have to do the following to get max and min values from axisX():

        @
        QDateTimeAxis dtax=dynamic_cast<QDateTimeAxis*>(axisX());
        QValueAxis valax=dynamic_cast<QValueAxis>(axisX());
        @

        Then check for which one came back NULL. If DateTime, then do the conversion as you suggest. If Value, then simply make a call to min() and max().

        Because I cant get qreal min() from a QDateTimeAxis, it is more lines of code.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved