Results 1 to 4 of 4

Thread: How can i replace big text in QLegendItem

  1. #1
    Join Date
    Sep 2011
    Posts
    13
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How can i replace big text in QLegendItem

    Hellow!
    How can i replace big text in the QLegendItem, for example:
    I have this text "x^2+12325*x+14124", how can i do that program replace this on the "x^2...124"
    In advance many thanks for your help!

  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: How can i replace big text in QLegendItem

    Well if your question is about this particular text you can simply set the shorter string as curve title.

    A more general solution is to overload QwtPlotItem::updateLegend():
    Qt Code:
    1. void YourCurve::updateLegend( QwtLegend *legend ) const
    2. {
    3. if ( legend == NULL )
    4. return;
    5.  
    6. QwtPlotCurve::updateLegend( legend );
    7.  
    8. QwtLegendItem *label = qobject_cast<QwtLegendItem *>( legend->find( this ) );
    9. if ( label )
    10. {
    11. QwtText text = title();
    12. ...
    13. label->setText( ... );
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 
    Unfortunately there is no support for Qt::TextElideMode in the Qwt layout system yet,

    Uwe

  3. #3
    Join Date
    Sep 2011
    Posts
    13
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How can i replace big text in QLegendItem

    It is question not about particular text, there are any text

  4. #4
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How can i replace big text in QLegendItem

    the solution Uwe suggested is not about particular text as well. Suppose you set your curve a title. That title is what you want to appear in the legend. In updateLegend function, title() gives that title you have set. Now suppose you want only 10 chars max in your title...then take out the first 4 chars of string, append with '...' then take out the last four chars of string and append, etc...

Similar Threads

  1. [solved]QString.replace()
    By Qiieha in forum Qt Programming
    Replies: 1
    Last Post: 16th September 2011, 09:15
  2. Replies: 3
    Last Post: 23rd May 2011, 14:36
  3. Replies: 3
    Last Post: 3rd May 2009, 08:58
  4. QString - find and replace text
    By graciano in forum Newbie
    Replies: 3
    Last Post: 24th January 2009, 20:35
  5. Replace text
    By Hz in forum Qt Programming
    Replies: 2
    Last Post: 22nd March 2006, 08:16

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.