I'm trying to figure out what the best way is to calculate a fixed width needed for a QwtScaleWidget.
Here's my issue:
I've got an application with multiple QwtPlots aligned vertically on pages of a QTabWidget. The plots all share a common x-axis and are meant to stay vertically aligned, but the y-axis values can vary greatly between individual plots. As the y-axis min/max change on individual plots due to data values changing, the width of the QwtScaleWidget changes to accommodate, causing the plots to shift around a little which just looks funny to the user. For example, if the y-axis max changes from 10 to 1000, the scale needs to grow a little bit wider to accommodate the additional zeroes, and since the parent widget isn't resizing, the plot shrinks a little bit in width. I then need to resize all the other plots to the same width to keep them lined up. This looks somewhat visually jarring.
I do know up front what the absolute data limits could be (our highest value can't be greater than 5 digits long). So rather than have the scale widget auto resize based on current text string lengths, I'd prefer to just set them to the width needed for our data maximum, even if that means often times they'll be wider than strictly necessary. To be clear, I still want the values of the scale to auto-scale, I just don't want the current values of the scale to affect the width of the widget.
So I know could use QFontMetrics and my largest allowed value to figure out how many pixels I need to accommodate the longest string based on the current font, but what other parameters do I need to know, and how do I get access to them? Looking at the widget in action, it appears that I also need to take into account the width of the tick marks, probably some sort of spacing in between the text and the tick marks, and then maybe some margin around everything?
I can't quite tell from the documentation if
int QwtScaleWidget::dimForLength (int length, const QFont &scaleFont) const
To copy to clipboard, switch view to plain text mode
is intended to do what I want? If it is, I'm not sure what I'm supposed to put in for the length parameter?
Bookmarks