Results 1 to 3 of 3

Thread: Qwt Legend item/entry set checked programmatically. How?

  1. #1

    Default Qwt Legend item/entry set checked programmatically. How?

    I can check an entry in a qwt_legend by a mousecklick but how can I achive this programmatically.
    I can hide or show a plotcurve but the representation of the curve in the legend is always unchecked

    I searched the internet for a clue but found nothing really usefull.

  2. #2

    Default Re: Qwt Legend item/entry set checked programmatically. How?

    Sorry, I forgot to write some example code.
    My Code
    QwtLegend *legend = new QwtLegend;
    legend->setDefaultItemMode( QwtLegendData::Checkable );
    m_plotter->insertLegend( legend, QwtPlot::RightLegend );
    connect( legend, SIGNAL( checked( const QVariant &, bool, int ) ), SLOT( legendChecked( const QVariant &, bool ) ) );
    QwtPlotCurve *curve = new QwtPlotCurve(name);
    curve->setItemAttribute(QwtPlotItem::Legend, true);
    curve->setPen( color );
    curve->attach( m_plotter );
    I can show the curve by code but the legenditem isn't automatically checked.

    Added after 1 3 minutes:

    With this semi "solution" I can check every item in the legend but I want to check only specific items in the legend
    QObjectList obj_lst = m_plotter->legend->contentsWidget()->children();
    int sz = obj_lst.size();
    for(QObject* obj : obj_lst)
    QString str = obj->objectName();
    std::string stdStr = str.toStdString();
    QwtLegendLabel *lgdItem = dynamic_cast<QwtLegendLabel*>(obj);

    if(lgdItem != NULL)
    Last edited by JackieN; 5th September 2014 at 10:03.

  3. #3
    Join Date
    Feb 2006
    Munich, Germany
    Thanked 860 Times in 809 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    MacOS X Unix/X11 Windows

    Default Re: Qwt Legend item/entry set checked programmatically. How?

    Setting a legend item checked is done in several Qwt examples, where you can find the code. F.e the tvplot example - or in scaleengine/transformplot you even find a method "setLegendChecked( QwtPlotItem * )", that does an exclusive check ( unchecking all others ).
    The missing link between plot items and legend items is to use QwtPlot::itemToInfo().

    Last edited by Uwe; 5th September 2014 at 10:13.

Similar Threads

  1. Legend item with SVN trunk
    By bigjoeystud in forum Qwt
    Replies: 1
    Last Post: 7th August 2012, 20:33
  2. On Press Space Key item in QTreeWidget gets checked.
    By merry in forum Qt Programming
    Replies: 3
    Last Post: 9th January 2012, 10:19
  3. Legend Checked from start
    By AlphaWolfXV in forum Qwt
    Replies: 2
    Last Post: 12th January 2011, 22:15
  4. Replies: 2
    Last Post: 13th September 2008, 14:55
  5. Checked item in QTreeWidget?
    By vishal.chauhan in forum Qt Programming
    Replies: 18
    Last Post: 3rd January 2008, 21:18


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.