changing QLabel font size(label created on the graphicsView)
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);
Code:
m_textOCOG
= new QLabel(m_view
->viewport
());
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
Re: changing QLabel font size(label created on the graphicsView)
I just tested and it works for me. What does this output?
Code:
qDebug() << info.family() << info.pointSize();
Re: changing QLabel font size(label created on the graphicsView)
easy question:
What should there be included to use qDebug? Anything added to the .pro file?
Maverick
Re: changing QLabel font size(label created on the graphicsView)
#include <QtCore/QtDebug>
Re: changing QLabel font size(label created on the graphicsView)
"Helvetica" 20
This is the result.
Maverick
Re: changing QLabel font size(label created on the graphicsView)
This is what was expected right ?
Re: changing QLabel font size(label created on the graphicsView)
This works, right?
Code:
// main.cpp
#include <QtGui>
int main(int argc, char *argv[])
{
label
->setFont
(QFont("Helvetica",
20,
QFont::Bold));
view.show();
return a.exec();
}
Re: changing QLabel font size(label created on the graphicsView)
Yes it works . Not working in "my" view though.
Maverick
Re: changing QLabel font size(label created on the graphicsView)
Then, are you by any chance adjusting the font of the label anywhere else? And which other widgets do you set a font explicitly?
Re: changing QLabel font size(label created on the graphicsView)
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.
Re: changing QLabel font size(label created on the graphicsView)
Are you by any chance using static or global instances of QFont ?
Re: changing QLabel font size(label created on the graphicsView)
I am using an (auto) local font object.
Maverick