PDA

View Full Version : QwtPolarMarker and QwtLegend



lokida
28th March 2011, 09:47
Hi,

I use a QwtPolarMarker but it does not appear in the legend. I have looked at the documentation but have found nothing about this. Try to use legend->insert but dont'know which widget I should pass to this method.

Any help would be welcome.

Thank you.

Uwe
28th March 2011, 10:16
marker->setItemAttribute( QwtPolarItem::Legend, true );
Uwe

lokida
28th March 2011, 10:23
Thank you.
And note for myself, read completely the documentation...

So, I have the marker in the legend but the associated symbol is not displayed in the legend.
Probably an other option that I haven't read in the documentation or is ti normal ?

Thanks.

Uwe
29th March 2011, 07:18
The default representation of a plot item on the legend is its title and QwtPolarMarker has no special implementation - probably it should have one.

With Qwt 5.x and QwtPolar 1.0 you have to implement something like this:


virtual void YourMarker::updateLegend(QwtLegend *legend) const
{
QwtPolarMarker::updateLegend( legend );
QwtLegendItem *label =
dynamic_cast<QwtLegendItem *>( legend->find(this) );
if ( label )
{
label->setSymbol( symbol() );
label->setIdentifierMode(
QwtLegendItem::ShowSymbol | QwtLegendItem::ShowText );
}
}

With Qwt 6.x + QwtPolar from SVN trunk you have to implement something like this:


virtual void YourMarker::drawLegendIdentifier(
QPainter *painter, const QRectF &rect ) const
{
QSize symbolSize = symbol()->boundingSize();
symbolSize -= QSize( 2, 2 );

// scale the symbol size down if it doesn't fit into rect.

double xRatio = 1.0;
if ( rect.width() < symbolSize.width() )
xRatio = rect.width() / symbolSize.width();

double yRatio = 1.0;
if ( rect.height() < symbolSize.height() )
yRatio = rect.height() / symbolSize.height();

const double ratio = qMin( xRatio, yRatio );

painter->save();
painter->scale( ratio, ratio );

symbol()->drawSymbol( painter, rect.center() / ratio );

painter->restore();
}

Uwe

lokida
29th March 2011, 09:00
Hi,

That perfectly works !

Thank you.