How to change font on drawText?

QString str = QString::number((double)i, 'd', 1); painter->drawText(100 + i * 800/9 - 6, 910, 40, 40, 0, str ); 

I would like to increase fontSize to 2x, what is displayed?

+4
source share
3 answers

You can try something like this (non-compiled code to see if it works!):

 QFont font = painter->font() ; /* twice the size than the current font size */ font.setPointSize(font.getPointSize() * 2); /* set the modified font to the painter */ painter->setFont(font); /* draw text etc. */ painter.drawText(....); 
+19
source

It revealed:

 QFont font; font.setPixelSize(12); for(int i = 0; i < 10; i++){ painter->drawLine(100, 100 + i * 800/9, 900, 100 + i * 800/9); str = QString::number((double)9 - i, 'd', 1); painter->setFont(font); painter->drawText(75, 100 + i * 800/9 - 6, 40, 40, 1, str); } 
+3
source

this is the easiest way

 painter.setFont(QFont("times",22)); //22 is a number which you have to change 
+1
source

Source: https://habr.com/ru/post/1493048/


All Articles