Results 1 to 2 of 2

Thread: Overloading drawColumn method of QwtPlotHistogram

  1. #1
    Join Date
    Dec 2010
    Posts
    33
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Overloading drawColumn method of QwtPlotHistogram

    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
    Qt Code:
    1. class Histogram: public QwtPlotHistogram
    2. {
    3. public:
    4. Histogram(const QString &, const QColor &);
    5. void setColor(const QColor &);
    6. void setValues(uint numValues, const double *);
    7. void drawColumn(QPainter *painter,const QwtColumnRect &rect,const QwtIntervalSample &samples);
    8. };
    To copy to clipboard, switch view to plain text mode 
    and wrote this function
    Qt Code:
    1. void Histogram::drawColumn(QPainter *painter,const QwtColumnRect &rect,const QwtIntervalSample &sample)
    2. {
    3. drawColumn(painter,rect,samples);
    4. QString s="My Text";
    5. painter->drawText(50,100,s);
    6. }
    To copy to clipboard, switch view to plain text mode 
    I dont know what i'm missing out, because no text appeared at all with this

  2. #2
    Join Date
    Oct 2013
    Posts
    1
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Overloading drawColumn method of QwtPlotHistogram

    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) ;
    }
    }

Similar Threads

  1. Replies: 8
    Last Post: 5th January 2011, 11:51
  2. QwtPlotHistogram
    By yers in forum Qwt
    Replies: 4
    Last Post: 5th January 2011, 07:23
  3. Replies: 4
    Last Post: 4th January 2011, 09:47
  4. Replies: 1
    Last Post: 25th November 2010, 11:37
  5. overloading ++ --
    By mickey in forum General Programming
    Replies: 13
    Last Post: 4th January 2008, 18:55

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
  •  
Qt is a trademark of The Qt Company.