4 Attachment(s)
Ensure margin for QwtPlotMarkers? And enlarge legend font?
Hi again,
I have some marker text items (QwtPlotMarker) in my plot, located at desired (x,y) locations. All looks good, except in some cases when the plot is rescaled and parts of some
markers end up outside the visible part of the canvas. The plot itself has a connected QwtPlotRescaler since It's important for me to keep the aspect ratio of the plotted curves. See examples in the attached pictures.
Attachment 12641 Attachment 12642 Attachment 12643
Now I wonder if there is a way to take care of this so that the markers are always visible, regardless of how I rescale the plot? Can I somehow find out to what Y axis limits I need to set so that the (top and bottom) marker texts can fit, also if I should change font size of the markers? Or is there some other way to handle it? I would prefer not to set too large Y axis interval just to "be sure", rather as small as possible but still så that all text fits. (Hm, could this question be understood..?)
The next question is about font size of the QwtPlotLegend. I've tried to increase the font size this way:
Code:
QFont lFont
= legend
->font
();
lFont.setPointSize(18);
legend->setFont(lFont);
plot
->insertLegend
(legend,
QwtPlot::TopLegend,
1.0);
plot->updateLegend();
However, this seems to have no effect, regardless of the size I set in setPointSize(...).
An example here, showing how my plot looks now (and I would really like a bit larger font for the legend):
Attachment 12644
Ideas?
Many thanks in advance!
Re: Ensure margin for QwtPlotMarkers? And enlarge legend font?
One more comment, or rather a question, which, if I find some answer to it probably could help me solve the "margin" issue I'm facing.
I thought that if I could find out the size of the QwtPlotMarker in terms of the coordinates of the plot, I could use this to simply adjust the Y axis limits when needed. I know of course the position of the marker, since I "placed" it in the plot with myPlotMarker->setValue( ), but still I would need to find out the extent of the resulting plot marker text "rect" in the plot, in terms of the plot coordinate X and Y limits. I assume this could be pretty simple, but I still cannot figure it out... Any bright ideas out there? :)
Re: Ensure margin for QwtPlotMarkers? And enlarge legend font?
Not 100% sure if I got all the details ...
But maybe it is simply "marker->label()->textSize( ).height() + marker->label()->spacing()" what you are looking for. Note that this is a value in widget ( != plot ) coordinates.
As you already found a way, that the position of the marker is always inside you could try using QwtPlotLayout::setCanvasMargin() - also a value in widget coordinates.
Otherwise you would need to use the scaleMaps to translate the pixels into plot coordinates. But then you have the same chicken/egg problem as the rescaler: the scale maps depend on the plot intervals - those you want to find out by using the scale maps.
Of course you could also consider to overload QwtPlotMarker::drawLabel() and modify the layout code. so that the labels always stay inside of the boundaries of the canvas.
Uwe
Re: Ensure margin for QwtPlotMarkers? And enlarge legend font?
Thanks for your reply! Feels like I'm able to fix my margin issue, thanks to your advice. For now I will use the QwtPlotLayout::setCanvasMargin() approach, together with "marker->label()->textSize( ).height() + marker->label()->spacing()". It seems to be pretty simple and promising at a first glance.
Regarding the font size of the legend in my plot: I still have not been able to "force" a larger font, so any hints here would also be most welcome.
Best regards!
Re: Ensure margin for QwtPlotMarkers? And enlarge legend font?
Quote:
Originally Posted by
dobedidoo
Regarding the font size of the legend in my plot:
The code you have posted is correct, you can try it f.e in the bode example.
Uwe