PDA

View Full Version : qwt 6.1.0 - QwtPlotMarker label truncated by edge of plot



csteury
16th January 2015, 21:33
Hello, I have created a label for a QwtPlotMarker. The vertical line is near the right edge of the plot and is truncated by the right edge of the plot/canvas.

10888

How can I make the plot take into account the label and make the plot a bit bigger? Struggling along I tried this:
m_wa_marker->setItemAttribute(QwtPlotItem::Margins, true); // more space???

Thanks in advance for your suggestions (btw - great library!)

cs


QwtPlotMarker *m_wa_marker;
void emat_attenuation_plot::set_wa_sample(double sample)
{
QString label = QString("WA: %1").arg(sample, 0, 'f', 1);
QwtText text(label);
text.setColor(Qt::blue);
text.setFont(QFont("Helvetica", 10, QFont::Bold));
m_wa_marker->setLabel(text);
m_wa_marker->setValue(sample, 0.0);
m_wa_marker->setItemAttribute(QwtPlotItem::Margins, true); // more space???
}

Uwe
18th January 2015, 11:09
One idea how to avoid this problem might be to implement some sort of auto alignment feature. F.e you could overload QwtPlotMarker::drawLabel(), where you change the alignment to left, when there is not enough space.

If this is not possible you have to decide if you want to (a) extend the plot coordinate system or you want to (b) extend the margin between the end of the axis and the canvas border. IMO a) would be more natural, but here you have the problem, that the text size is in widget coordinates, while the axis is in plot coordinates. So you would always have to readjust, when the widget gets resized, or the axis is changing.

For b) setting the QwtPlotItem::Margins flag should be the correct idea, but you also need to overload QwtPlotMarker::getCanvasMarginHint() where you return something for the right margin - depending on the text size.

Uwe

csteury
19th January 2015, 21:04
I did as you suggested in b) and it worked as you described. But ... it looked funny/"off-balance" since the plot stuck out only to accommodate the text. I then realized there was a much simpler solution which worked better anyway for my particular problem. Since the plot-data's character, labels and samples are mostly constant it worked very well to just plot the marker-text to the :AlignLeft side of the vertical marker-line and leave it at that. Problem solved!
10892
Nonetheless it was a good Qwt exercise for the reader in how to approach customizing the plot elements. Thanks for the help!

cs
cs