PDA

View Full Version : how to create the legends which is having line & symbol?



mammaiap
30th June 2011, 11:10
Hi Friends,

i wanted to show the legends in such a way that it should show lines with symbols...

but LegendAttributes doesnot have such option ...it will allow either LegendShowLine or LegendShowSymbol...

like below:

"defaultcurve->setLegendAttribute(QwtPlotCurve::LegendShowLine,tr ue);
defaultcurve->setLegendAttribute(QwtPlotCurve::LegendShowSymbol, true);"

can anyone please suggest how i can achieve the legends which is having both lines with symbols?

Thanks & Regards,
Muthu

Uwe
3rd July 2011, 07:50
can anyone please suggest how i can achieve the legends which is having both lines with symbols?
You already posted the correct code.

Unfortunately the layout/render code for the legend is pretty bad in Qwt 6 and you might have effects like that the line is covered by the symbol.

Uwe

mammaiap
6th July 2011, 12:18
Hi Uwe,

Thanks for your reply...

but what i can do to achieve this??

Regards,
mammaiap

Uwe
7th July 2011, 07:03
Well, the first step is to test your legend with a symbol in XCross style, that doesn't cover all space below its bounding rectangle. If the line is visible now we know that both are really painted.

One possible solution to solve your problem is to increase the width for the identifier, so you can see the line in the additional space. This can be done somehow this way:


class YourCurve: public QwtPlotCurve
{
public:
...

virtual void updateLegend( QwtLegend *legend ) const
{
QwtLegendItem *legendItem =
qobject_cast<QwtLegendItem *>( legend->find( this ) );
if ( legendItem )
{
QSize sz = symbol()->boundingSize();
legendItem->setIdentifierSize(
QSize( 3 * sz.width(), sz.height() ) );
}

QwtPlotItem::updateLegend( legend );
}
};

Uwe