PDA

View Full Version : Simple Problem with QFont (point size)



mtrpoland
31st December 2007, 16:19
Quick question.
I want my QLabel present a text of 2pt size. I thought the code below would be correct. It is not as no matter what number I put instead of 2 the size stays the same (~12pt). How can I force smaller text?



QFont mainHeaderFont("Helvetica [Cronyx]",2,QFont::Normal);
mainHeader.setFont(mainHeaderFont);

marcel
31st December 2007, 16:26
Do you have "Helvetica [Cronyx]" installed?
What happens if you simply use "Helvetica"?

EDIT: Are you sure 2pt is a wise font size? Because at a resolution of 1680x1050 I can't even see a text with font size 2. Just tested it in Designer.

mtrpoland
31st December 2007, 16:33
Nothing.
The problem is size, not the font family.
I see ~12pt letters and I want it 2pt (or a bit bigger, anyway much smaller than what I see).

The code:


OrangeInquirer::OrangeInquirer(QWidget *parent) : QWidget(parent) {
setFixedSize(300,300);

mainHeader.setText(tr("Your result will be saved as soon as\n you fill the input area and click ok."));
qDebug(qPrintable(QString::number(mainHeader.fontI nfo().pointSize())));
//the code above shows always 9!!
mainHeader.setParent(this);
QFont mainHeaderFont("Helvetica",6,QFont::Normal);
mainHeader.setFont(mainHeaderFont);
qDebug(qPrintable(QString::number(mainHeader.fontI nfo().pointSize())));
//but the code above shows always 6 !! but the size does not change
mainHeader.setGeometry(5+35+10,5+25+10,280-2*35-2*10,40);
}

marcel
31st December 2007, 16:45
what widget is mainHeader and in what context do you use it? i see it's created on the stack... or is it a member of some class?

mtrpoland
31st December 2007, 16:49
mainLabel is a private member of OrangeInquirer

I found


Warning: Do not use this function in conjunction with Qt Style Sheets. The font of a widget can be customized using the "font" style sheet property.

in QWidget::setFont(QFont &) doc...
It does not say clearly that such combination would not work...