How to change font size of QwtLegend?

2.2k views Asked by At

I want to change the font size of my QwtLegend.

I tried

QFont label_font("Helvetica");
label_font.setPointSize(20);

QwtLegend *legend = new QwtLegend();
legend->setFont(label_font);
plot->insertLegend(legend, QwtPlot::TopLegend, 1.0);

and

QFont label_font("Helvetica");
label_font.setPointSize(20);

QwtLegend *legend = new QwtLegend();
plot->insertLegend(legend, QwtPlot::TopLegend, 1.0);
plot->legend()->setFont(label_font);

But both ways do not work. What is wrong here? How can I change the font size of QwtLegend items?

1

There are 1 answers

0
Max Schreiber On

Seems like the font is taken from the legend's parent. I wrote the font into the plot's stylesheet and it worked.

myPlot = new QwtPlot(parent);
myPlot->setStyleSheet("background-color:black; color:yellow; 
                       border-radius: 0px; font: 8pt \"Deja Vu\";");

QwtLegend *thelegend =new QwtLegend(myPlot);
myPlot->insertLegend(thelegend, QwtPlot::BottomLegend, 0.0);