Results 1 to 3 of 3

Thread: QwtLegend items disappear when checked off

  1. #1
    Join Date
    Jan 2011
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QwtLegend items disappear when checked off

    I've got a plot with a legend that initially appears ok. However, when I click on an item in the legend to deselect it (uncheck it?) it is not only unchecked, but it disappears from the legend entirely. Furthermore, I never get a signal when an item on the legend is clicked.

    Here is part of my code (I have left out quite a bit of code from this class):
    In the constructor of my class, plot_ is a QwtPlot*:
    Qt Code:
    1. QwtLegend * legend = new QwtLegend();
    2. legend->setItemMode(QwtLegend::CheckableItem);
    3. legend->setWhatsThis("Click on an item to show/hide the plot");
    4. plot_->insertLegend(legend, QwtPlot::RightLegend);
    5. connect(plot_, SIGNAL(legendChecked(QwtPlotItem *, bool)),this,
    6. SLOT(showCurve(QwtPlotItem *, bool)));
    To copy to clipboard, switch view to plain text mode 

    Later on, when I add a new curve (newSpec is a QwtPlotSpectrogram* ):
    Qt Code:
    1. newSpec->setItemAttribute(QwtPlotItem::Legend, true); // add to the clickable legend
    2. newSpec->updateLegend(plot_->legend());
    To copy to clipboard, switch view to plain text mode 

    I assume the two problems (signal not set up correctly, items disappearing) are related but I can't figure out why or how to solve it. Thank you very much!

    Edit: forgot to mention, if this helps, the itemCount() of the legend does change (decreases by 1) when one of the legend items disappears.
    Last edited by steve123; 16th May 2011 at 21:09.

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

    Default Re: QwtLegend items disappear when checked off

    Check the cpuplot example,

    Uwe

  3. #3
    Join Date
    Jan 2011
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QwtLegend items disappear when checked off

    Hi Uwe,

    Thanks for your quick reply. It turns out I should not have been using attach() but rather setVisible, as your example does. Thanks!
    Last edited by steve123; 17th May 2011 at 13:58. Reason: figured it out

Similar Threads

  1. Replies: 2
    Last Post: 2nd September 2010, 19:52
  2. QwtLegend size
    By baray98 in forum Qwt
    Replies: 0
    Last Post: 10th May 2010, 05:26
  3. items in view would disappear on scrolling
    By sepehr in forum Qt Programming
    Replies: 4
    Last Post: 21st March 2009, 07:20
  4. QTableWidget: set items disappear after new insertion
    By Raccoon29 in forum Qt Programming
    Replies: 6
    Last Post: 16th March 2008, 18:28
  5. Iterate and get Checked QTable items??
    By darpan in forum Newbie
    Replies: 2
    Last Post: 10th May 2006, 18:27

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.