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.
void SingleLogTrack::slotSimplifyLegend(bool on) { // works for Qwt 6.0
bool showit = true;
if ( plt_item
->rtti
() == QwtPlotItem::Rtti_PlotCurve ) {
if (on) showit = c->isVisible();
if (!on) {
QWidget *w
= legend
()->find
(plt_item
);
if ( w && w->inherits("QwtLegendItem" ) ) {
}
}
}
}
}
void SingleLogTrack::slotSimplifyLegend(bool on) { // works for Qwt 6.0
bool showit = true;
foreach (QwtPlotItem *plt_item, itemList()) {
if ( plt_item->rtti() == QwtPlotItem::Rtti_PlotCurve ) {
QwtPlotCurve *c = (QwtPlotCurve*)(plt_item);
if (on) showit = c->isVisible();
c->setItemAttribute(QwtPlotItem::Legend,showit);
if (!on) {
QWidget *w = legend()->find(plt_item);
if ( w && w->inherits("QwtLegendItem" ) ) {
((QwtLegendItem *)w)->setChecked(c->isVisible());
}
}
}
}
}
To copy to clipboard, switch view to plain text mode
void SingleLogTrack::slotSimplifyLegend(bool on) { // not yet working for Qwt 6.1
bool showit = true;
if ( plt_item
->rtti
() == QwtPlotItem::Rtti_PlotCurve ) {
if (on) showit = c->isVisible();
if (!on) {
QwtLegend *lgd
= qobject_cast<QwtLegend
*>
(legend
());
QList<QWidget *> legendWidgets = lgd->legendWidgets(itemToInfo(plt_item));
if ( legendWidgets.size() == 1 ) {
QwtLegendLabel *b = qobject_cast<QwtLegendLabel *>(legendWidgets[0]);
if ( b && b->inherits("QwtLegendLabel") )
((QwtLegendLabel *)b)->setChecked(c->isVisible());
}
}
}
}
}
void SingleLogTrack::slotSimplifyLegend(bool on) { // not yet working for Qwt 6.1
bool showit = true;
foreach (QwtPlotItem *plt_item, itemList()) {
if ( plt_item->rtti() == QwtPlotItem::Rtti_PlotCurve ) {
QwtPlotCurve *c = (QwtPlotCurve*)(plt_item);
if (on) showit = c->isVisible();
c->setItemAttribute(QwtPlotItem::Legend,showit);
if (!on) {
QwtLegend *lgd = qobject_cast<QwtLegend *>(legend());
QList<QWidget *> legendWidgets = lgd->legendWidgets(itemToInfo(plt_item));
if ( legendWidgets.size() == 1 ) {
QwtLegendLabel *b = qobject_cast<QwtLegendLabel *>(legendWidgets[0]);
if ( b && b->inherits("QwtLegendLabel") )
((QwtLegendLabel *)b)->setChecked(c->isVisible());
}
}
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks