PDA

View Full Version : Overloading drawColumn method of QwtPlotHistogram



penny
6th January 2011, 04:45
I want to set text on the rectangles of a QwtPlotHistogram. I read in a post that i need to overload drawColumn method of QwtPlotHistgram, but i cannot figure out what exactly is to be done..

I wrote

class Histogram: public QwtPlotHistogram
{
public:
Histogram(const QString &, const QColor &);
void setColor(const QColor &);
void setValues(uint numValues, const double *);
void drawColumn(QPainter *painter,const QwtColumnRect &rect,const QwtIntervalSample &samples);
};
and wrote this function

void Histogram::drawColumn(QPainter *painter,const QwtColumnRect &rect,const QwtIntervalSample &sample)
{
drawColumn(painter,rect,samples);
QString s="My Text";
painter->drawText(50,100,s);
}
I dont know what i'm missing out, because no text appeared at all with this

AtillaBaspinar
9th October 2013, 20:42
I think you need to call the super class function:

QwtPlotHistogram::drawColumn(painter,rect,samples) ;

I am dealing with same problem. What I need is to make the bars of the histogram in different colors. I also override drawColumn() function. It compiles but it does not paint bars to different colors.
My piece of code is like that:
void Histogram::drawColumn(QPainter *painter, const QwtColumnRect &rect, const QwtIntervalSample &samples) const
{
if (samples.value > 35)
{
painter->setPen(Qt::yellow);
painter->setBrush(QBrush((Qt::yellow)));
QwtPlotHistogram::drawColumn(painter,rect,samples) ;

}
else
{
painter->setPen(Qt::blue);
painter->setBrush(QBrush((QColor(60,100,20))));
QwtPlotHistogram::drawColumn(painter,rect,samples) ;
}
}