PDA

View Full Version : How to use QwtLegend?



ashley1
3rd November 2015, 12:13
The documentation around Qwt widgets isn't great, and can't find any simple examples on how to get started with QwtLegend. I'd like a simple legend on the right or bottom of a my bar chart representing that red bars are 'negative change' and blue bars are 'positive'. Could anyone provide an example? Any help or direction would be much appreciated.

HappyCoder
3rd November 2015, 13:04
Qwt has it's own examples in subdir of your source code:
.\examples
.\playground

In subdir examples you will find the example "legends".

If you want to have a legend inside your canvas use QwtPlotLegendItem

ashley1
3rd November 2015, 13:28
Qwt has it's own examples in subdir of your source code:
.\examples
.\playground

In subdir examples you will find the example "legends".

If you want to have a legend inside your canvas use QwtPlotLegendItem

The examples don't do anything I want - they all demonstrate how to plot legends for each curve. I'd like to just create a custom legend from scratch

Uwe
3rd November 2015, 14:17
The examples don't do anything I want - they all demonstrate how to plot legends for each curve. I'd like to just create a custom legend from scratch
When your legend is completely unrelated to the plot items you can simply use QLabels and arrange plot and labels in some QLayout.

Otherwise you would need to provide more details: how many bar items do you have and which attributes of them do you want to display how on your legend.

Uwe

HappyCoder
3rd November 2015, 14:24
[...] that red bars are 'negative change' and blue bars are 'positive'

add to ONE red bar the QwtPlotItem::ItemAttribute that it should be shown in legend, all other false
add to ONE blue bar the QwtPlotItem::ItemAttribute that it should be shown in legend, all other false