Hi everyone,
I want to have a QwtPlotLegendItem fully positionable, not only with Qt::Alignment and setMargins.
So, in the legends example, I modified the class Legend like this:
class LegendItem: public QwtPlotLegendItem
{
public:
LegendItem()
{
setTextPen( color );
#if 1
setBorderPen( color );
c.setAlpha( 200 );
setBackgroundBrush( c );
#endif
}
virtual QRect geometry
(const QRectF &canvasRect
) const { QRect rect
= QwtPlotLegendItem
::geometry( canvasRect
);
rect.moveTopLeft( m_pos );
return rect;
}
void setPosition
(const QPoint &pos
){ m_pos = pos;
itemChanged();
}
};
class LegendItem: public QwtPlotLegendItem
{
QPoint m_pos;
public:
LegendItem()
{
setRenderHint( QwtPlotItem::RenderAntialiased );
QColor color( Qt::white );
setTextPen( color );
#if 1
setBorderPen( color );
QColor c( Qt::gray );
c.setAlpha( 200 );
setBackgroundBrush( c );
#endif
setPosition(QPoint(0,25));
}
virtual QRect geometry(const QRectF &canvasRect) const {
QRect rect = QwtPlotLegendItem::geometry( canvasRect );
rect.moveTopLeft( m_pos );
return rect;
}
void setPosition(const QPoint &pos){
m_pos = pos;
itemChanged();
}
};
To copy to clipboard, switch view to plain text mode
It works fine on the plot, the legend top left corner is at position (0,25) of the canvas, but when I export in a pdf file using QwtPlotRenderer, then the position of the legend is not correct (see the attached file), it is shifted by I don't know how much in the left and top direction. What am I doing wrong here?
Thank you for your help
Bookmarks