Results 1 to 5 of 5

Thread: Hiding and displaying legend items not working in 6.1 as did in 6.0

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2008
    Location
    California, USA
    Posts
    18
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Hiding and displaying legend items not working in 6.1 as did in 6.0

    Hi,
    I'm porting to Qwt 6.1 from 6.0 and am having touble getting legend items to hide and display themselves, depending on wheather they are being displayed in a QwtPlot chart. Any hints? Any help much appreciated.

    Below is a method for 6.0 that worked, and below that is the same method i'm trying to implement for 6.1 that doesn't work. All of the code below implemented in a QwtPlot subclass.

    Qt Code:
    1. void SingleLogTrack::slotSimplifyLegend(bool on) { // works for Qwt 6.0
    2. bool showit = true;
    3. foreach (QwtPlotItem *plt_item, itemList()) {
    4. if ( plt_item->rtti() == QwtPlotItem::Rtti_PlotCurve ) {
    5. QwtPlotCurve *c = (QwtPlotCurve*)(plt_item);
    6.  
    7. if (on) showit = c->isVisible();
    8. c->setItemAttribute(QwtPlotItem::Legend,showit);
    9.  
    10. if (!on) {
    11. QWidget *w = legend()->find(plt_item);
    12. if ( w && w->inherits("QwtLegendItem" ) ) {
    13. ((QwtLegendItem *)w)->setChecked(c->isVisible());
    14. }
    15. }
    16.  
    17. }
    18. }
    19. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void SingleLogTrack::slotSimplifyLegend(bool on) { // not yet working for Qwt 6.1
    2. bool showit = true;
    3. foreach (QwtPlotItem *plt_item, itemList()) {
    4. if ( plt_item->rtti() == QwtPlotItem::Rtti_PlotCurve ) {
    5. QwtPlotCurve *c = (QwtPlotCurve*)(plt_item);
    6.  
    7. if (on) showit = c->isVisible();
    8. c->setItemAttribute(QwtPlotItem::Legend,showit);
    9.  
    10. if (!on) {
    11. QwtLegend *lgd = qobject_cast<QwtLegend *>(legend());
    12. QList<QWidget *> legendWidgets = lgd->legendWidgets(itemToInfo(plt_item));
    13.  
    14. if ( legendWidgets.size() == 1 ) {
    15. QwtLegendLabel *b = qobject_cast<QwtLegendLabel *>(legendWidgets[0]);
    16. if ( b && b->inherits("QwtLegendLabel") )
    17. ((QwtLegendLabel *)b)->setChecked(c->isVisible());
    18. }
    19. }
    20.  
    21. }
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by EliGri; 31st May 2013 at 00:43. Reason: added [code] and [/code] tags

Similar Threads

  1. Spacing around legend items
    By FilipeMaia in forum Qwt
    Replies: 5
    Last Post: 13th August 2015, 09:15
  2. Replies: 1
    Last Post: 12th May 2011, 22:41
  3. Printing plot with many legend items
    By coppermine in forum Qwt
    Replies: 1
    Last Post: 11th March 2011, 10:18
  4. Replies: 2
    Last Post: 2nd September 2010, 19:52
  5. Replies: 1
    Last Post: 15th May 2010, 18:22

Tags for this Thread

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.