Results 1 to 5 of 5

Thread: How to add/change text in a qwtlegend?

  1. #1
    Join Date
    Aug 2017
    Posts
    9
    Thanks
    7
    Qt products
    Qt5
    Platforms
    Windows

    Default How to add/change text in a qwtlegend?

    Hi,

    I'm working on migrating a project which based on QWT 5.1 to QWT 6.2.
    I found the QwtLegendItem was removed in QWT6.2. I used setSymbol() and setText() to get the legend symbol/icon and legend text from my QwtLegend.

    I try to use QwtLegendLabel to get text, but there is not setSymbol() in QwtLegendLabel. Hence, I can't add any symbol/icon into my QwtLegendLabel object.

    So I plan to create a new Legend and change the its text directly.
    But how to change the text contents in a QwtLegend?

    Or how can I get the legend symbol/icon from a QwtLegend?

    Thanks a lot!

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

    Default Re: How to add/change text in a qwtlegend?

    Since Qwt 6 the information on the legend is more under control of the corresponding plot item. F.e the icon is created by QwtPlotItem::legendIcon(), what can be overloaded - like everything what finally ends up on the legend.

    If you provide more information about what exactly you need to achieve I can give more detailed hints.

    Uwe

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

    lin3398032 (23rd May 2018)

  4. #3
    Join Date
    Aug 2017
    Posts
    9
    Thanks
    7
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to add/change text in a qwtlegend?

    Hi Uwe,

    I implemented an external Legend in my project which is based on Qwt 6.1 now (the external legend like below picture).
    2.PNG

    There is a feature that can read the point data in the curve, then I want to add the data of the point to the external legend (like below picture). The blue circle is the point data. This picture is from the old version project which is based on Qwt 5.1.
    1.PNG


    In Qwt 5.1, I used a QwtLegendItem instance to set the symbol that related with the external legend and set the text contents(point data and curve name), then put it into a QFrame object for showing.

    Since QwtLegendItem is removed in Qwt6.1, I used QwtLegendlabel to replace QwtLegendItem, but it hasn't setSymbol function. Hence, it only show the text contents right now (like below picture).
    3.jpg


    I thought QwtLegendLabel cannot used in this case now. So I'm looking for a method that can add text in to the external legend so that I can use it to show the point data.

    Thanks a lot!

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

    Default Re: How to add/change text in a qwtlegend?

    As said before: the content of the legend entries is under control of the plot item now:

    If you want to change the text ( without changing the title of the item ) you can overload QwtPlotItem::legendData().
    Having a look at the implementation in qwt_plot_item.cpp will help to understand how it works.

    Uwe

    PS: You might be interested in QwtPlotLegendItem

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

    lin3398032 (1st June 2018)

  7. #5
    Join Date
    Aug 2017
    Posts
    9
    Thanks
    7
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to add/change text in a qwtlegend?

    Hi Uwe,

    Thanks a lot!
    I figured out my problem by overloading legendData(). It works!

Similar Threads

  1. Replies: 4
    Last Post: 19th July 2016, 20:10
  2. Replies: 0
    Last Post: 23rd February 2011, 17:36
  3. How to change the Label text
    By grsandeep85 in forum Qt Programming
    Replies: 2
    Last Post: 15th September 2009, 13:57
  4. Replies: 1
    Last Post: 23rd May 2008, 09:24
  5. Replies: 8
    Last Post: 15th May 2007, 10:21

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.