PDA

View Full Version : changing QLabel font size(label created on the graphicsView)



maverick_pol
16th August 2007, 11:49
HI guys,

I have created QLabel on the QGraphicsView widget, but I can't set the font size. HEre is the code I am using, and it's not changing the font( I have a standardt (point 12) font);


m_textOCOG = new QLabel(m_view->viewport());
QFont font("Helvetica", 20, QFont::Bold);
m_textOCOG->setFont(font);
m_textOCOG->setText("COG: N A");
m_textOCOG->setGeometry(452,10,100,20);
m_textOCOG->setFrameStyle(QFrame::NoFrame);
m_textOCOG->show();


Any idea? Thank you beforehand.

Maverick

jpn
16th August 2007, 13:29
I just tested and it works for me. What does this output?


QFontInfo info(font);
qDebug() << info.family() << info.pointSize();

maverick_pol
16th August 2007, 13:36
easy question:
What should there be included to use qDebug? Anything added to the .pro file?

Maverick

Gopala Krishna
16th August 2007, 13:46
#include <QtCore/QtDebug>

maverick_pol
16th August 2007, 13:53
"Helvetica" 20

This is the result.

Maverick

Gopala Krishna
16th August 2007, 14:09
This is what was expected right ?

jpn
16th August 2007, 14:12
This works, right?


// main.cpp
#include <QtGui>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QGraphicsView view;
QLabel* label = new QLabel("COG: N A", view.viewport());
label->setFont(QFont("Helvetica", 20, QFont::Bold));
view.show();
return a.exec();
}

maverick_pol
16th August 2007, 14:38
Yes it works . Not working in "my" view though.

Maverick

jpn
16th August 2007, 14:42
Then, are you by any chance adjusting the font of the label anywhere else? And which other widgets do you set a font explicitly?

maverick_pol
16th August 2007, 14:48
I've tried changing the font size in the other "part" of the program and it works fine.
Give me 10 minutes and I will find the stupid mistake of mine.

All in all thank you for help.

Maverick


It looks like ... when I try to set the font outside the constructor it works fine. While my function setting the font is placed inside the constructor there is no "change in display" even though the qDebug says it has changed.

Gopala Krishna
16th August 2007, 17:39
Are you by any chance using static or global instances of QFont ?

maverick_pol
17th August 2007, 09:36
I am using an (auto) local font object.

Maverick