How to use explicit labels/ticks?
Hi, I have very newbie-style problem.
I've written this code:
Code:
#include "qwt_plot.h"
#include "qwt_scale_div.h"
#include <QApplication>
int main(int argc, char ** argv) {
plot.setCanvasBackground(Qt::white);
plot.
setAxisScale(QwtPlot::yLeft,
0,
50);
QList<double> ticks = QList<double>()
<< 10
<< 40
<< 90;
plot.
setAxisScaleDiv(QwtPlot::yLeft, pressScaleDiv
);
plot.show();
return app.exec();
}
My wish is, that y axis has ticks and labels at values 10, 40, 90.
It seems like code above gives no effect - labels are at 0, 10, 20, 30, 40, 50 + intermediate ticks.
What am I doing wrong?
I suspect that the error is trivial :o ....
Re: How to use explicit labels/ticks?
A QwtScaleDiv consists of the range of a scale and the positions of its ticks. Your code creates an invalid QwtScaleDiv object for 2 reasons:
- it doesn't have a range
- QwtScaleDiv::isValid() is only true, when using the constructor with a valid range
The second reason is left over from the very early Qwt versions - it should have never been like this. That's why the isValid() flag has been removed in Qwt 6.1.
Uwe
PS: The line with setAxisScale() is pointless, when you assign a different scale a couple of lines below
Re: How to use explicit labels/ticks?
Thanks, Uwe.
I've improved my wonderful code:
Code:
#include "qwt_plot.h"
#include "qwt_scale_div.h"
#include <QApplication>
int main(int argc, char ** argv) {
plot.setCanvasBackground(Qt::white);
QList<double>(),
QList<double>(),
QList<double>()
<< 10
<< 40
<< 90
};
// QwtScaleDiv pressScaleDiv;
// pressScaleDiv.setInterval(0, 100);
// pressScaleDiv.setTicks(
// QwtScaleDiv::MinorMajor,
// QList<double>()
// << 10
// << 40
// << 90
// );
plot.
setAxisScaleDiv(QwtPlot::yLeft, pressScaleDiv
);
plot.show();
return app.exec();
}
and it works - but when I use the commented section instead of the working one above - it doesn't. No problem for me, anyway.
Thanks a lot.
Re: How to use explicit labels/ticks?
Quote:
Originally Posted by
ssample
but when I use the commented section instead of the working one above - it doesn't.
That's because of what I wrote as 2.). The code would be o.k. for Qwt 6.1, but all earlier versions ( starting with Qwt 0.1 ) have this nasty QwtScaleDiv default constructor.
Uwe