2013-07-23 44 views

回答

2

想通了:

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

如果你有一個不同於默認**的字體**,它可能會重置它而不是隻是修改它的大小。 –

+1

setFont不應該在for循環中... – Troyseph

19

你可以嘗試這樣的事情(未編譯的代碼,看看它是否有效!):

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(....); 
+0

In may case: '''font.setPointSize(font.pointSize()* 2);''' – danger89

0

這是最簡單的方式

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