Results 1 to 6 of 6

Thread: Avoiding Truncated Labels

Threaded View

Previous Post Previous Post   Next Post Next Post
  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

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.