PDA

View Full Version : QwtPlot -> axis -> Draw labels for all kind of ticks ?



gufeatza
16th March 2010, 13:37
Hy there!

I believe my question is understandable from the title of the post :), but I got to be sure:

I have a QwtPlot with a time axis as the x axis (as in cpluplot example of Qwt) and my wish is to draw labels not only for the major ticks of the axis, instead I want labels (maybe just milliseconds, not the entire time) for all ticks.

Any help is welcomed. Thanks a lot!

gufeatza
16th March 2010, 15:23
Heh, I finally found the way to do this.

QwtScaleDraw also implements this virtual method:

void draw(QPainter *painter, const QPalette& palette) const;

So I override it, executed the code that was executing before and added label support also for medium and minor ticks:

void X::draw(QPainter *painter, const QPalette& palette) const
{
QwtScaleDraw::draw(painter, palette);

if ( hasComponent(QwtAbstractScaleDraw::Labels) )
{
painter->save();
painter->setPen(palette.color(QPalette::Text)); // ignore pen style

painter->setFont(QFont("Verdana", 7));

const QList<double> &mediumTicks = scaleDiv().ticks(QwtScaleDiv::MediumTick);

for (int i = 0; i < (int)mediumTicks.count(); i++)
{
const double v = mediumTicks[i];
if ( scaleDiv().contains(v) )
drawLabel(painter, mediumTicks[i]);
}

painter->setFont(QFont("Verdana", 6));

const QList<double> &minorTicks = scaleDiv().ticks(QwtScaleDiv::MinorTick);

for (int i = 0; i < (int)minorTicks.count(); i++)
{
const double v = minorTicks[i];
if ( scaleDiv().contains(v) )
drawLabel(painter, minorTicks[i]);
}

painter->restore();
}
}