How do I get crowded QLegend items to wrap?
-
I'm building a chart that can end up with many lines/series and this causes the legend area to be too packed and the text condensed and unreadable as they all show up on one line. Is there any way to get the items in the legend to wrap to multiple lines?
-
@mmikeinsantarosa
Until you get an answer from someone who knows what he's talking about...:
If it can be done at all,-
see https://doc.qt.io/qt-5/qlegendmarker.html#setLabel. You could try setting that, or the series name, to contain a
\n
, cross fingers, and if that works, it might (kind of) "wrap"? -
https://doc.qt.io/qt-5/qlegend.html#showToolTips-prop says "This property holds whether tooltips are shown when the text is truncated.", so there must be a way to "truncate the text"?
-
https://www.qtcentre.org/threads/67441-qchart-hide-legend-for-part-of-series shows you can hide a legend completely, you could manage by showing only certain legend(s) at a time when many series or something?
-
https://doc.qt.io/qt-5/qtcharts-legend-example.html lets you display the legend elsewhere yourself, if that's of any interest. It shows setting a rectangle for the legend, I don't quite understand whether that's only when it's detached or whether you can re-attach with your own size
Several things to look at for you :)
-
-
Well, detaching the legend does allow for for the items to wrap but then it's next to impossible to determine where the legend should show up by default without landing on top of important trend lines.
There's got to be a way to manipulate an attached legend.
I did see a way to create a custom legend in QML https://doc.qt.io/qt-5/qtcharts-qmlcustomlegend-example.html but I'm not using QML. Everything I have is built in creator & C++.
-
hi @mmikeinsantarosa .could you resolve this issue?how did u make all the legends visible ?thank you.