Results 1 to 4 of 4

Thread: QwtLegend problem

  1. #1
    Join Date
    Jan 2020
    Posts
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default QwtLegend problem

    Hi everyone,
    I have following situation:
    I use QwtPlot to plot something and I use QwtLegend to draw legend from it. I made it like this:
    mQwtLegend = new QwtLegend(mPlot); // mPlot is QwtPlot*
    mPlot->insertLegend(mQwtLegend, *mLegendCurrentPosition);
    The thing is I also made a checkbox for the user to decide whether something plotted should be visible or not.
    It works as intended, but my legend somehow still shows everything. I tried e.g.
    mPlot->updateLegend();
    after hiding the plot, unfortunately without results.
    From what I read, before newest version it was possible to get access to LegendItem and set visibility manually -> right now it's maintained in a way I don't understand and I cannot make it right.
    Could someone please help me with that?
    Thanks in advance :).

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

    Default Re: QwtLegend problem

    Quote Originally Posted by mimickxd View Post
    The thing is I also made a checkbox for the user to decide whether something plotted should be visible or not.
    It works as intended, but my legend somehow still shows everything.
    You could enable/disable the QwtPlotItem::Legend attribute ?

    Uwe

  3. #3
    Join Date
    Jan 2020
    Posts
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QwtLegend problem

    First of all, thanks for fast reply,

    with it I managed to solve this issue. Using setItemAttribute was the correct approach, but at the beginning it did nothing (or so I thought). I had to set attribute and then update Legend, step by step, only then it actually ran. If someone in the future is interested, that's the code:

    for (auto item : mPlot->itemList())
    {
    // code here to find intended item
    item->setItemAttribute(item->Legend, state); //state is defined as true or false
    mPlot->updateLegend();
    break;
    }

    Thank you for your help .

    EDIT:

    OK, now I have another problem regarding this issue.

    While legend is showing/hiding properly, using solution mentioned above does following thing:
    I have signal A (pos. 1) and B (pos. 2) in menu and in legend.
    Now I hide A, so A is hidden in menu and in legend, only B is visible.
    Then I show A and A is shown again in menu and in legend, but in menu it's on its position while in legend the structure is now B, A (it's reverse).
    I assume that
    item->setItemAttribute(item->Legend, state);
    disables the attribute ergo removes given signal from legend, and showing it means actually "adding it to the legend list".
    When I do this with e.g.3 signals, hidden signal, while shown again, goes to the end of the legend.

    Am I right here and is there a way to repair that behaviour?
    Last edited by mimickxd; 30th January 2020 at 12:27.

  4. #4
    Join Date
    Jan 2020
    Posts
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QwtLegend problem

    Sorry, it was doubled somehow. Still - does anybody know how to solve issue mentioned in EDIT above ?

Similar Threads

  1. How to use QwtLegend?
    By ashley1 in forum Qwt
    Replies: 4
    Last Post: 3rd November 2015, 14:24
  2. qwtlegend
    By Surfman19 in forum Qwt
    Replies: 6
    Last Post: 6th August 2015, 19:02
  3. Qwt 6.1.0 trunk and QwtLegend
    By carhun in forum Qwt
    Replies: 0
    Last Post: 22nd August 2012, 09:13
  4. QwtPolarMarker and QwtLegend
    By lokida in forum Qwt
    Replies: 4
    Last Post: 29th March 2011, 09:00
  5. QwtLegend Position changing problem?
    By umituzun84 in forum Qwt
    Replies: 1
    Last Post: 19th March 2010, 13:25

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.