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 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.

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,325
    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, 15:46
  2. Replies: 7
    Last Post: 21st February 2017, 17:11
  3. QListView: how to adding column text?
    By richardander in forum Qt Programming
    Replies: 2
    Last Post: 31st December 2013, 10:40
  4. QTextEdit : adding Text at the Same Location
    By Saptarshi4031 in forum Qt Programming
    Replies: 3
    Last Post: 2nd July 2010, 09:04
  5. Replies: 3
    Last Post: 22nd January 2010, 16: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
  •  
Qt is a trademark of The Qt Company.