Results 1 to 7 of 7

Thread: adding generic text to a legend

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2018
    Location
    Gouda, the Netherlands
    Posts
    5
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default adding generic text to a legend

    Hi,

    How can I add generic extra text to a legend?
    Text that is independent from the curves.

  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: adding generic text to a legend

    What exactly do you want t achieve - having additional entries on the legend or having a different text than the title of the corresponding plot item ?

    Uwe

  3. #3
    Join Date
    Jul 2018
    Location
    Gouda, the Netherlands
    Posts
    5
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: adding generic text to a legend

    Quote Originally Posted by Uwe View Post
    What exactly do you want t achieve - having additional entries on the legend or having a different text than the title of the corresponding plot item ?

    Uwe
    Additional entries to the legend.
    Some extra meta-data.

  4. #4
    Join Date
    Nov 2006
    Location
    Dresden, Germany
    Posts
    108
    Thanks
    9
    Thanked 12 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: adding generic text to a legend

    Hi ??? [flok],

    create a new curve object, set line attribute to NoLine, set legend text, add to plot. It will show up in the legend, but not paint anything in the plot.

    Bye,
    Andreas
    Andreas

  5. #5
    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: adding generic text to a legend

    When doing this hack it would be enough to add a dummy QwtPlotItem with the QwtPlotItem::Legend attribute being enabled.
    But of course it is also possible to add entries manually to the legend, by calling QwtLegend::updateLegend - even if calling this method is due to its "over-abstraction" kind of hard to use.

    Uwe

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

    flok (23rd January 2019)

  7. #6
    Join Date
    Jul 2018
    Location
    Gouda, the Netherlands
    Posts
    5
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: adding generic text to a legend

    Ok I succeeded in adding entries by:

    void addToLegend(const QString & key, const QStringList & what, QwtAbstractLegend *const legend)
    {
    QList<QwtLegendData> list;

    for(QStringList::const_iterator it = what.begin(); it != what.end(); it++) {
    QwtLegendData data;
    data.setValue(QwtLegendData::Role::TitleRole, QVariant(*it));

    list << data;
    }

    legend->updateLegend(QVariant(key), list);
    }

    then I do:
    QStringList le;
    le.append("hello");
    le.append("bicycle");
    le.append("1");

    addToLegend("key", le, graph -> legend());

    Unfortunately when calling this, say, two times, the layout gets messed up: the order of the items becomes seemingly random.
    Is there a way in which I can either sort them or keep them in the same order as added?
    I also tried adding items individually and them giving them a key-in-order (a, b, c, etc) but that did not help.

  8. #7
    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: adding generic text to a legend

    Qwt is open source - you can check/debug what is going on in your case easily.
    Maybe also have a look at the stockchart example, that shows how to implement a totally different type of legend.

    HTH,
    Uwe

Similar Threads

  1. Replies: 9
    Last Post: 24th November 2017, 16:46
  2. Replies: 7
    Last Post: 21st February 2017, 18:11
  3. QListView: how to adding column text?
    By richardander in forum Qt Programming
    Replies: 2
    Last Post: 31st December 2013, 11:40
  4. QTextEdit : adding Text at the Same Location
    By Saptarshi4031 in forum Qt Programming
    Replies: 3
    Last Post: 2nd July 2010, 10:04
  5. Replies: 3
    Last Post: 22nd January 2010, 17:46

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.