I was using check box as legend item, but the requirement now changes to display multiple lines for single legend. For example legend text "F_JD20F2_MSSQL_ERROR F_JT01E4_INTEG_UNRECOV_FAIL_FREQ F_JT0207_INTEG_NOT_SAVEABLE F_JT04A1_NET_VERSION" needs to be displayed like
I thought it may be easier to use rich text. So my first attempt was to replace spaces with <br> in legend text then creates a legend item widget containing a checkbox and a label. The reason is that checkbox does not understand rich text.
Result turns out not to be satisfactory since labels are not aligned. Sample code is:
QWidget*
JBStatCurve::legendItem(void) const
{
QWidget *legend_tab= new QWidget(plot);
QHBoxLayout *legend_lay= new QHBoxLayout(legend_tab);
legend_lay->setSpacing(0);
legend_lay->setMargin(0);
QCheckBox *check_box= new QCheckBox("", legend_tab);
QPalette *palette= new QPalette();
palette->setColor(QPalette::Active, QColorGroup::Text, pen_color);
check_box->setPalette(*palette);
QObject::connect(check_box, SIGNAL(clicked(bool)),
plot, SLOT(legendItemClicked(bool)));
QLabel *label= new QLabel(legend_tab);
QString rich_text= title_text;
rich_text.prepend("<html><body>");
rich_text.append("</body></html>");
label->setText(rich_text);
legend_lay->addWidget(check_box);
legend_lay->addWidget(label);
return legend_tab;
Could anybody give me some advice? For instance, is my direction is wrong or implementation is wrong?