Results 1 to 4 of 4

Thread: QwtDateScaleDraw understading

  1. #1
    Join Date
    May 2016
    Posts
    8
    Thanks
    2

    Default QwtDateScaleDraw understading

    Hi,

    I'm have trouble understanding how the QwtDateScaleDraw properties works, I'would like to draw a plot from an array of dates and one of doubles (both comes from database). I've been struggling at the very beggining just to display my date in a particular format, such as dd/mm/yyyy.

    I've done several tests to try to understand how things works but I'm stucked.

    here is where i'm at the moment :

    Qt Code:
    1. //My dates values convert to double (as i think it works )
    2. //firstDate and lastDate are the first and the last QDate value of my array of dates
    3.  
    4. double minValue=QwtDate::toDouble(QDateTime(firstDate));
    5. double maxValue=QwtDate::toDouble(QDateTime(lastDate));
    6.  
    7. QwtPlot *plot= new QwtPlot();
    8.  
    9. QwtDateScaleDraw* scaleDraw= new QwtDateScaleDraw(Qt::LocalTime);
    10. scaleDraw->setDateFormat(QwtDate::Day,"dd/mm/yy");
    11.  
    12. plot->setAxisScaleDraw(QwtPlot::xBottom,scaleDraw);
    13. plot->setAxisScale(QwtPlot::xBottom, minValue,maxValue);
    To copy to clipboard, switch view to plain text mode 

    I do have the correct first and last values but they are displayed with hour, mins, sec and ms. My dates can variate from day to year (f.e values 1 : 2000/01/01 value 2 : 2000/01/20 value 3 : 2000/04/01 value 4 : 2002/01/01), what i mean is that i have a huge range of values. and so i don't care about the hour and lesser values.

    Among all of this when i've tried to use the QwtDateScaleEngine, it just messes up all of my layout organisation. (I add my plot to a layout which is inside a layout with fixed size)

    So here is my questions :

    Does QwtDatmScaleEngine change layout disposition ?
    Do you know anything that could help me trying to figure out how to get familiar with the dates qwt functions (besides examples which i've had a look at) ?

    Sorry for my english/programation level.

    Thanks in advance,
    Stank.

    EDIT : Actually I checked again and I do not have the correct first value displayed on my X axis (I've got the day before instead);
    Last edited by Stank; 4th May 2016 at 14:41.

  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: QwtDateScaleDraw understading

    Quote Originally Posted by Stank View Post
    Does QwtDateScaleEngine change layout disposition ?
    You have an effect of the label created by the QwtDateScaleDraw object and the positions of the ticks calculated by the engine. But this effect is not different to any other type of scale - the space for displaying a label simply needs to be somethere. There are a couple of options how to control, where the internal layout tries to find the space, but without knowing your situation ...

    Uwe

  3. #3
    Join Date
    May 2016
    Posts
    8
    Thanks
    2

    Default Re: QwtDateScaleDraw understading

    Hi,

    Thank you very much for your reply.

    I have a main window which I have used showMaximized on.
    Qt Code:
    1. ui->setupUi(this);
    2. this->showMaximized();
    To copy to clipboard, switch view to plain text mode 
    I've have then added two main items :
    a scrollArea and a tabWidget
    Qt Code:
    1. QScrollArea* scrollArea = new QScrollArea;
    2. ui->layout->addWidget(scrollArea,1,0,1,4);
    3. //The tabWidget is created in Designer but filled with line codes and I have placed it for it to fill the rows I wanted
    4. ui->layout->addWidget(ui->tabWidget,1,5,1,9);
    To copy to clipboard, switch view to plain text mode 

    I have one of the tabs that contains my plot (and 4 buttons).
    Qt Code:
    1. layoutTab1->addWidget(button1,0,0);
    2. layoutTab1->addWidget(button2,0,1);
    3. layoutTab1->addWidget(button3,0,2);
    4. layoutTab1->addWidget(button4,0,3);
    5. layoutTab1->addWidget(myPlot,2,0,1,5);
    6. ui->tab1->setLayout(layoutTab1);
    To copy to clipboard, switch view to plain text mode 
    I have tried to put sizeConstraint on my layoutTab1 but it had no effect, and a sizeFixed on my mainLayout didn't do the trick either.

    I don't know if it's relevant for my problem, but I need to display different plots depending on the button choosed, so I've put all my plots on the same place and hide/show them when a button is clicked.

    I have now added curves to my plot but I still have this issue with my date format and my scale engine. I m aware that I'm probably doing it wrong, but as I said earlyer this one of my first Qt Project. Sorry if I'm still missing informations.

    Thanks for your help,

    Stank

  4. #4
    Join Date
    May 2016
    Posts
    8
    Thanks
    2

    Default Re: QwtDateScaleDraw understading

    This is not the solution i was aiming for but it worked :

    I solved my scale problem at the same time as my format problem using this method :
    (original post in french) : http://www.developpez.net/forums/d10...-axe-absisses/
    overight the QwtText label function :

    Qt Code:
    1. class TimeScaleDraw: public QwtScaleDraw
    2. {
    3. virtual QwtText label(double v) const
    4. {
    5. QDateTime t = QDateTime::fromTime_t((int)v); //cf fromTime_t
    6. return t.toString("dd/MM/yyyy");
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

    and then
    Qt Code:
    1. myPlot->setAxisScaleDraw(QwtPlot::xBottom, new TimeScaleDraw());
    2. myPlot->setAxisScale(QwtPlot::xBottom, min, max);
    To copy to clipboard, switch view to plain text mode 
    where min and max are values in second since epoch.

    Thanks for your time

    Stank

Similar Threads

  1. Replies: 3
    Last Post: 1st February 2016, 09:04
  2. Replies: 1
    Last Post: 14th October 2015, 08:29

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.