Results 1 to 5 of 5

Thread: How to draw aligned elements next to QwtLegendItem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2011
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to draw aligned elements next to QwtLegendItem

    Hi.

    I have the next problem. I need draw number next to text of legend's item.

    This number is changeable and all numbers must be aligned in one column for each legend's item.

    For example:

    first legend item 23.00
    second legend item 900.00
    third legend item 3.00


    I tried to implement the next solution. I subclassed QwtLegenItem and overrided function drawText. Then I was finding the legend's item with maximal width, converted its width in pixels with help QwtMetricsMap and used function drawText several times.
    Qt Code:
    1. void XRealTimeLegendItem::drawText(QPainter *painter, const QRect &rect)
    2. {
    3. QString currentValue = QString().setNum( currentItemValue->value() );
    4.  
    5. QFontMetrics fontMetrics = painter->fontMetrics();
    6. const QwtMetricsMap &map = QwtPainter::metricsMap();
    7.  
    8. int maxItemWidth = map.screenToLayoutX( fontMetrics.width( maxItemName ) );
    9.  
    10. painter->drawText( rect, text().text() );
    11.  
    12. QRect valueRect = rect;
    13. valueRect.setX( rect.right() - rect.width() + maxItemWidth + 2 * spacing() );
    14. painter->drawText( valueRect, currentValue );
    15. }
    To copy to clipboard, switch view to plain text mode 

    But print of QwtPlot doesn't work for this solution. The result of print is

    first legend item
    second legend item
    third legend item

    without numbers!

    How can I draw numbers aligned in one column with correct print ?
    Last edited by maxomato; 23rd February 2011 at 14:20. Reason: updated contents

Similar Threads

  1. Replies: 0
    Last Post: 18th January 2011, 03:19
  2. Painting a right-aligned text
    By curreli in forum Newbie
    Replies: 2
    Last Post: 29th July 2010, 17:49
  3. QwtPlotItem inverting qwtPlot scale
    By jmsbc in forum Qwt
    Replies: 1
    Last Post: 25th August 2009, 15:09
  4. Replies: 3
    Last Post: 16th May 2009, 11:16

Tags for this Thread

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.