Hi.
I have the next problem. I need draw number next to text of legend's item.
This number is changeable and all numbers must be aligned in one column for each legend's item.
For example:
first legend item 23.00
second legend item 900.00
third legend item 3.00
I tried to implement the next solution. I subclassed QwtLegenItem and overrided function drawText. Then I was finding the legend's item with maximal width, converted its width in pixels with help QwtMetricsMap and used function drawText several times.
void XRealTimeLegendItem
::drawText(QPainter *painter,
const QRect &rect
) {
int maxItemWidth = map.screenToLayoutX( fontMetrics.width( maxItemName ) );
painter->drawText( rect, text().text() );
valueRect.setX( rect.right() - rect.width() + maxItemWidth + 2 * spacing() );
painter->drawText( valueRect, currentValue );
}
void XRealTimeLegendItem::drawText(QPainter *painter, const QRect &rect)
{
QString currentValue = QString().setNum( currentItemValue->value() );
QFontMetrics fontMetrics = painter->fontMetrics();
const QwtMetricsMap &map = QwtPainter::metricsMap();
int maxItemWidth = map.screenToLayoutX( fontMetrics.width( maxItemName ) );
painter->drawText( rect, text().text() );
QRect valueRect = rect;
valueRect.setX( rect.right() - rect.width() + maxItemWidth + 2 * spacing() );
painter->drawText( valueRect, currentValue );
}
To copy to clipboard, switch view to plain text mode
But print of QwtPlot doesn't work for this solution. The result of print is
first legend item
second legend item
third legend item
without numbers!
How can I draw numbers aligned in one column with correct print ?
Bookmarks