Draw Text on QCustomPlot

2k views Asked by At

I have a problem with drawing text on QCustomPlot widget. A have a several graphs in my widget and each of them carry the information about amplitude in its name. A would like to display that text when the user clicks on graph at the position of cursor. I have this code but its not working although when I enable MessageBox, value displays well:

QCustomPlot *nahlad; //graph
connect(nahlad,    SIGNAL(plottableClick(QCPAbstractPlottable*,QMouseEvent*)), 
   this, SLOT(kliknutieNaGraf(QCPAbstractPlottable*,QMouseEvent*)));
...   

void resultWindow::kliknutieNaGraf(QCPAbstractPlottable *a, QMouseEvent *b) 
{
    QPainter *paint = new QPainter(); paint->drawText( QPoint(b->x(),b->y()), 
        QString("Amplituda je: %1").arg(a->name()) );
    //QMessageBox::about(NULL, QString("Info"), QString("%1").arg(a->name()));
}
1

There are 1 answers

0
Pavel On

If I understand your code correctly, you seem to paint the text directly with QPainter but to no effect (QPainter needs somewhere to paint).

Why not use the built-in QCPItemText? There is a nice tutorial on how to use it.

Let me know if you need further explanation or a piece of code.

S pozdravom, Pavel