Re: Place a chart's legend inside an ancestor
I'd like to take a chart's legend and place it inside one of the chart's siblings. The idea is that I have several charts laid out horizontally which all share the same range (y axis).
In this particular case, my widget hierarchy looks something like this:
...
- QSplitter
- - QwtPlot
- - - QwtLegend
- - QwtPlot
- - - QwtLegend
- - QwtPlot
- - - QwtLegend
The legends are all redundant, so it wastes a lot of space. I'd rather it look something like this:
...
- QSplitter
- - QwtLegend
- - QwtPlot
- - QwtPlot
- - QwtPlot
Can this be done? How?
Added after 8 minutes:
It looks like QwtPlot doesn't even provide a way to remove a legend once it's been added.
Re: Place a chart's legend inside an ancestor
You might want to use Qwt 6.1 with its new architecture for the plot legends. A legend ( could be a QwtLegend, but any other widget as well - see the stockchart example ) simply connects to a signal of the plot:
Code:
void legendDataChanged
( const QwtPlotItem *plotItem,
const QList<QwtLegendData>
&data
)
QwtPlot::insertLegend() is still available to insert the legend into the layout system of a plot, but this is optionally. You could also put a legend somewhere in your application layout and connect as many plots as you want to it - by doing the signal/slot connections manually.
3 notes:
- QwtPlot::ExternalLegend has to be replaced by not inserting the legend and setting up the signal/slots connection manually
- Don't be confused, that legendDataChanged emits a list of entries for one plot item. Usually the list will have 1 or 0 entries, but f.e. QwtPlotMultiBarChart needs to show more than entry.
- Unfortunately I will have to modify the API of QwtLegend, so that Qwt 6.1 will be usable for the qwtpolar package as well. But the only consequence for application code will be, that it might have to add some casts for QwtPlotItem.
Uwe
PS: A inserted legend can be removed by: QwtPlot::insertLegend( NULL ).
Re: Place a chart's legend inside an ancestor
Thanks for the quick reply. I'll try out QWT 6.1, should be no problem for my project.
I tried calling QwtPlot::insertLegend( NULL ). but I get segfault when I do that (svn 6.0.3).
Re: Place a chart's legend inside an ancestor
Quote:
Originally Posted by
stephelton
I tried calling QwtPlot::insertLegend( NULL ). but I get segfault when I do that (svn 6.0.3).
Should be a problem of your code - ask your debugger.
Qwt 6.1 also comes with a new example called legends, that plays with legends - including a new plot item for displaying a legend on the canvas.
Uwe