Results 1 to 6 of 6

Thread: Avoiding Truncated Labels

  1. #1
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Avoiding Truncated Labels

    G'day All,

    I've been experimenting with the Qwt histogram and cpuplot examples trying to produce a chart on a time axis. The labels on my x axis are rotated dates. The rightmost date was slightly truncated at its top-right extremity but I fixed that with a bit of code lifted from the cpuplot example. The left most label in my graph (see blue box below) is badly truncated. The time labels in the cpuplot example are not similarly truncated.

    The plot layout code looks like:
    Qt Code:
    1. QwtPlot plot;
    2. plot.setMargin(5);
    3. plot.setCanvasBackground(QColor(Qt::white));
    4. plot.setTitle("Hours by Month");
    5. plot.setAxisTitle(QwtPlot::yLeft, "Hours");
    6. plot.setAxisTitle(QwtPlot::xBottom, "Date");
    7. plot.setAxisScaleDraw(QwtPlot::xBottom,
    8. new TimeScaleDraw(QDate::currentDate()));
    9. plot.setAxisLabelRotation(QwtPlot::xBottom, -50.0);
    10. plot.setAxisLabelAlignment(QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom);
    11.  
    12. // From cpuplot example to stop rightmost label being truncated
    13. QwtScaleWidget *scaleWidget = plot.axisWidget(QwtPlot::xBottom);
    14. const int fmh = QFontMetrics(scaleWidget->font()).height();
    15. scaleWidget->setMinBorderDist(0, fmh / 2);
    To copy to clipboard, switch view to plain text mode 
    a bunch of code building QwtScaleDiv tick data, then
    Qt Code:
    1. QwtScaleDiv sd(-(double)(numValues+1), 1.0, vl);
    2. plot.setAxisScaleDiv(QwtPlot::xBottom, sd);
    To copy to clipboard, switch view to plain text mode 
    followed by an essentially unmodified (colours aside) histogram example.

    I thought it might be a z-order issue with the y-axis scale overwriting, but I couldn't find a way to change this. What do I need to tweak to sort this out?

    Regards,
    Chris

    Qwt 5.2.0, Qt 4.5.1, Linux
    Attached Images Attached Images

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Avoiding Truncated Labels

    In general the layout engine of QwtPlot should stretch the bottom scale below the left one, so that there is space enough for the tick labels of the bottom scale. And this is exactly what happens in the cpuplot example.

    From your code snippet it is difficult to say, what's wrong in your application. Your screenshot might be from a situation, where the layout has not been recalculated (missing replot) after you have assigned your scale properties. ( You can manually resize the plot window to check this. )

    If you compare your code with the cpuplot example - can you see any substantial differences ?

    Uwe

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Avoiding Truncated Labels

    G'day Uwe,

    Thanks for your reply. Resizing the window does not alter the x scale: the truncated labels stay truncated. I cannot see any operative part of the cpuplot example that affects this; as you say, it seems to be the default behaviour.

    I have attached the full source If you'd like to look (and forgive the blatant plagiarism ).

    Regards,
    Chris

    Edit: Had a bit more of a play with this. If I explicitly set
    Qt Code:
    1. plot.setAxisScale(QwtPlot::xBottom, -100, 1);
    To copy to clipboard, switch view to plain text mode 
    in the code attached then the label is good. If, as in my broken example, you leave this out (auto scale) the label is truncated. I can probably live with this in the intended application.
    Attached Files Attached Files
    Last edited by ChrisW67; 26th June 2009 at 03:18. Reason: Possible answer

  4. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Avoiding Truncated Labels

    The layout engine of QwtPlot assumes, that the first major tick is at the left and the last one is at the right side of the scale. But in your code its the other way round.

    I will think about how to fix this bug in Qwt ( manually generated ticks need to be ordered, after they have been passed with setScaleDiv).

    In the meantime you could simply turn the order of your ticks.

    Uwe

  5. The following user says thank you to Uwe for this useful post:

    ChrisW67 (7th July 2009)

  6. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Avoiding Truncated Labels

    Thanks Uwe. In rolling the code into a real application I had rewritten it the other way around anyway.

    I would not bother handling the tick marks in reverse order, just document that they should be left-to-right or bottom-to-top.

  7. #6
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Avoiding Truncated Labels

    Even better than documenting a bug is to fix it. ( Done in the 5.2 and trunk branches. )

    Uwe

Similar Threads

  1. Replies: 0
    Last Post: 17th April 2009, 08:58
  2. Tick Labels for Slider
    By jcraig in forum Qt Tools
    Replies: 2
    Last Post: 9th August 2007, 17:21
  3. setting QTreeWidget vertical labels
    By hyling in forum Qt Programming
    Replies: 2
    Last Post: 10th January 2007, 18:53

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.