Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change fontsize on drawText?

Tags:

c++

qt

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 showing?

like image 726
jdl Avatar asked Jul 23 '13 19:07

jdl


People also ask

How do you change the font on drawstring?

First create your g (or g2d) drawstring object String string = "Hello World"; then create a Font object Font stringFont = new Font( "SansSerif", Font. PLAIN, 18 ); Next set the Font object to the g or g2d object g2d. setFont( stringFont ); Now apply the g2d (or g) object to your drawstring object g2d.

How do I change font size in win11?

Open the Accessibility settings by pressing the Windows key + U. Look under Vision and click Text size. Adjust the Text size slider until the sample text in the Text size preview is easy to read. Click Apply.

How do you change text size in Java?

Object. setFont(new Font("Font-Style", Font-Weight, Font Size)); We use the same code as above keeping font styles the same while changing only the font size. We create a JLabel object (obj1) and assign a font size of 16 and another JLabel object (obj2) with a font size of 30.


2 Answers

You could try something like this (haven't compiled code to see if it works!):

QFont font = painter->font() ;

/* twice the size than the current font size */
font.setPointSize(font.pointSize() * 2);

/* set the modified font to the painter */
painter->setFont(font);

/* draw text etc. */
painter.drawText(....);
like image 198
Iosif Murariu Avatar answered Sep 19 '22 15:09

Iosif Murariu


Figured it out:

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);
}
like image 42
jdl Avatar answered Sep 21 '22 15:09

jdl