Results 1 to 3 of 3

Thread: Qwt Scale Draw

  1. #1
    Join Date
    Oct 2008
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11

    Unhappy Qwt Scale Draw

    Hi,

    I am new to both qt and qwt and I’m facing hell. I need some help in order to understand how to draw and set up a scale in qwt.

    My first question concerns the use of Qwt scale draw:

    1. Assume I have a set of time strings like 12:33:05 ,12:33:08, 12:33:11, 12:33:14, 12:33:17, 12:33:20. A total of 6. I want to use these as labels for major ticks.

    2 .Next, I have a x axis scale set up as : setAxisScale(QwtPlot::xBottom, 0, 60);

    3. Somehow qwt automatically divides the scale into 6 major divisions , each of 10 divisions each. This is acceptable for now but how do I change this default behavior in case?

    4. Next how do I assign a label to each major tick? I want the time string 12:33:05 to be the label of the first major tick and so on.


    my second question relates to the Cpu plot example:

    Qt Code:
    1. class TimeScaleDraw: public QwtScaleDraw
    2. {
    3. public:
    4. TimeScaleDraw(const QTime &base):
    5. baseTime(base)
    6. {
    7. }
    8. virtual QwtText label(double v) const
    9. {
    10. QTime upTime = baseTime.addSecs((int)v);
    11. return upTime.toString();
    12. }
    13. private:
    14. QTime baseTime;
    15. };
    To copy to clipboard, switch view to plain text mode 

    I would like to know which method actually calls the label and passes the parameter v.what exactly is the value of v? and who calls this method? in the example i understand that every second the setRawData is called for each curve.However i would like to know who calls the virtual method label?


    Hope you can help me answer these questions.

    Thanks,
    max.

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

    Default Re: Qwt Scale Draw

    Interval and all tick positions of a scale are stored in a QwtScaleDiv object.

    You can manually create a QwtScaleDiv and assign it to a plot axis (QwtPlot::setAxisScaleDiv()) , or you can use a QwtScaleEngine ( QwtPlot has one for each axis), that calculates it for you. When autoscaling ( QwtPlot::setAxisAutoScale() ) is enabled, the interval for the calculation of the scale is taken from the bounding rectangle of the plot items ( f.e. curves ), otherwise interval/step size are passed with QwtPlot::setAxisScale().

    The default scale engines try to calculate ticks for linear decimal scales, what doesn't need to be the right thing for date/time scales. ( QwtDateTimeScaleEngine is on my TODO list ). To improve your scale divisions you can derive and assign ( QwtPlot::setAxisScaleEngine()) your own scale engine or simply use QwtPlot::setAxisScaleDiv instead.

    QwtScaleDraw is responsible for painting a QwtScaleDiv. QwtScaleDraw::label() maps a tick value into a string.
    In the cpuplot example the values on the x-axis are seconds elapsed since the system is up. TimeScaleDraw::label() maps them into time strings - that's all.

    Uwe

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

    alizadeh91 (3rd September 2012)

  4. #3
    Join Date
    Oct 2010
    Location
    Bangalore
    Posts
    52
    Thanks
    8
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qwt Scale Draw

    use this class
    class TimeScaleDraw: public QwtScaleDraw
    {
    public:
    TimeScaleDraw(QString fmt) : format(fmt) { }

    virtual QwtText label(double v) const
    {
    QDateTime t = QDateTime::fromTime_t((int)v);
    return t.toString(format);
    }
    private:
    const QString format;
    };

    and set x-ais as below how many you want

    code snipet for filling samples

    void Graph::SetSamples(Curve *pCurve, QVector<double> *x , QVector<double> *y ,int size)
    {
    Xaxis = *x;
    Yaxis = *y;


    QDateTime pTimeEdit;
    pTimeEdit.setTime_t((unsigned int)x->at(0));
    unsigned int basetime = (unsigned int)x->at(0);
    unsigned int EndTime = (unsigned int)x->at(size-1);

    setAxisScaleDraw(QwtPlot::xBottom, new TimeScaleDraw("h:mm"));


    pCurve->setSamples(&Xaxis[0],&Yaxis[0] ,Xaxis.size());

    setAxisScale(QwtPlot::xBottom, basetime , EndTime ,0);

    replot();


    }

Similar Threads

  1. Replies: 5
    Last Post: 10th October 2008, 06:44
  2. Replies: 1
    Last Post: 9th October 2008, 07:23
  3. How can I draw needle for dial in Qwt
    By validator in forum Qwt
    Replies: 6
    Last Post: 3rd February 2008, 20:27
  4. qwt 5 log scale..
    By halberdier83 in forum Qwt
    Replies: 7
    Last Post: 12th November 2007, 07:21
  5. My own scale widget in Qwt
    By igrms in forum Qwt
    Replies: 7
    Last Post: 15th June 2006, 21:18

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.