PDA

View Full Version : Hi, how can I draw line & text in the specified area ?



navid
25th November 2013, 16:40
Hi all, how can I draw line & text in the specified area (please see enclosed picture) ?

Uwe
25th November 2013, 18:55
Are you talking about the legend ?

Uwe

navid
26th November 2013, 11:19
Hi Uwe,
I attached the final plot.

text and lines on top of the plot, show peaks position
text and lines on button of the plot, show area below curve between start & stop marks

navid
26th November 2013, 15:45
How can I draw plot same as the last enclosed paper picture?
Please example source code.

navid
27th November 2013, 10:41
Please introduce me with a start point

navid
27th November 2013, 17:32
Please ...
How can i draw line & text within legend?

Uwe
28th November 2013, 18:29
text and lines on top of the plot, show peaks position
text and lines on button of the plot, show area below curve between start & stop marks
Well, QwtPlot is a composite widget, that consists of a canvas, 4 scale widgets, a header, a footer and the legend.

Your picture shows a plot, where something is painted on the canvas above the canvas (a) and also something on the bottom scale, between the axis and the axis title (b).

For (a) you need to derive from QwtPlotCurve or implement a new type of plot item - don't now enough about the specific situation of your plot to recommend something. For (b) you need to derive from QwtScaleDraw, where you create the space for your extra labels by using setMinimumExtent().

Uwe

navid
30th November 2013, 14:27
Thanks for your reply.

I started with the following code:

class PlotCurve: public QwtPlotCurve
{
public:

PlotCurve(const QString &title = QString::null): QwtPlotCurve(title)
{
}

void setLabel(QString txt, QPointF pos)
{
data mydata;
mydata.pos = pos;
mydata.txt = txt;
strlst.append(mydata);
qDebug()<<"setLabel";

//try to run paintEvent

// this->show();
// this->plot()->update();

// QPaintEvent * pe = new QPaintEvent(QRect(pos.x(),pos.y(),100,20));
// this->paintEvent(pe);
}

void setLines()
{

}

void paintEvent(QPaintEvent *)
{
qDebug()<<"paintEvent";
QPainter * painter = new QPainter(this->plot()->paintEngine()->paintDevice());
painter->save();
for(int i=0; i < strlst.count(); i++) painter->drawText(strlst.at(i).pos,strlst.at(i).txt);
strlst.clear();
painter->restore();
}

private:

struct data{
QString txt;
QPointF pos;
};

QList<data> strlst;

};

but I can not run paintEvent !

I will be appreciated with your comments & suggestions.