problem with Font changing
Hi All.
In my application i'm changing the colour of window by applying .qss.
but while applying default.qss UI's font is remaining un affected . but while applying Pagefold.qss font is getting changed from ariel-12 to default or some thing.
i tried to solve like following
QFont font("font: Arial", 12, QFont::System);
qApp->setFont(font);
bhut its changing whole application font.
I need to change only QLabel font to arial-12.
Can any body help me. :(
Re: problem with Font changing
Try like QFont font("font: Arial", 12, QFont:referDefault);
qApp->setFont(font);"
Re: problem with Font changing
Quote:
Originally Posted by
sonuani
Try like QFont font("font: Arial", 12, QFont:referDefault);
qApp->setFont(font);"
I tried like this. but its changing size of all the ui linked to main ui. But i wanna to change the letter font size of only one. and ui name is Base. How to do it?:(
Re: problem with Font changing
Hi, why not using just
Try like QFont font("font: Arial", 12, QFont:referDefault);
ui.someLabel->setFont(font);
or something like this to change font only for a widgets you need?
qApp()->setFont will always change font for entire application and if i understood correctly, you need to change font only for several widgets, so you should use setFont method of those widgets.
If you intend to change font in whole ui (not concrete widgets) u may use styleSheet.
The simplest way to use a styleSheet is to open ui in qtdesigner, and paste something like
QLabel{font: bold italic "Times New Roman"; font-size:16}
in styleSheet Property of main ui's widget.
Re: problem with Font changing
Quote:
Originally Posted by
mchara
Hi, why not using just
Try like QFont font("font: Arial", 12, QFont:referDefault);
ui.someLabel->setFont(font);
or something like this to change font only for a widgets you need?
qApp()->setFont will always change font for entire application and if i understood correctly, you need to change font only for several widgets, so you should use setFont method of those widgets.
If you intend to change font in whole ui (not concrete widgets) u may use styleSheet.
The simplest way to use a styleSheet is to open ui in qtdesigner, and paste something like
QLabel{font: bold italic "Times New Roman"; font-size:16}
in styleSheet Property of main ui's widget.
Thanx. I tried like this. but the programm is getting terminated abnormaly.:(
Re: problem with Font changing
Which way did you tried?
if u are setting widgets font with
Try like QFont font("font: Arial", 12, QFont:referDefault);
ui.someLabel->setFont(font);
make sure it is done after setupUi() (in constructor) because setupUi() creates widgets in your ui - calling anything like ui.widget->method() before widget is initialized will cause crash.
if this isn't a reason try give a bit more detailed description of crash you have.
would be easier to find a solution if u would write anything about the problem ;)
so which method did u tried, when application crashes, where(maybe small part of code?), what debugger says etc.
Re: problem with Font changing
Quote:
Originally Posted by
mchara
Which way did you tried?
if u are setting widgets font with
Try like QFont font("font: Arial", 12, QFont:referDefault);
ui.someLabel->setFont(font);
make sure it is done after setupUi() (in constructor) because setupUi() creates widgets in your ui - calling anything like ui.widget->method() before widget is initialized will cause crash.
if this isn't a reason try give a bit more detailed description of crash you have.
would be easier to find a solution if u would write anything about the problem ;)
so which method did u tried, when application crashes, where(maybe small part of code?), what debugger says etc.
I tried like following
Ui::uiclassname ui; in .h
in constructor
setUp(this);
and inside function
i did like m_ui.centralwidget->setFont(font);
and its terminating abruptly.:(
Re: problem with Font changing
Let's be more precise, does your constuctor looks like this?
// SomeClass constructor.
SomeClass::SomeClass(QWidget *aParent)
:QWidget(aParent)
{
ui.setupUi(this);
QFont font("Arial", 16);
ui.someWidget->setFont(font);
ui.someWidget2->setFont(font);
}
because termination on ui.someWidget->setFont(font); call it's surely because ui.someWidget is not initialized correctly.
and did you tried other way with styleSheet?
Re: problem with Font changing
Quote:
Originally Posted by
mchara
Let's be more precise, does your constuctor looks like this?
// SomeClass constructor.
SomeClass::SomeClass(QWidget *aParent)
:QWidget(aParent)
{
ui.setupUi(this);
QFont font("Arial", 16);
ui.someWidget->setFont(font);
ui.someWidget2->setFont(font);
}
because termination on ui.someWidget->setFont(font); call it's surely because ui.someWidget is not initialized correctly.
and did you tried other way with styleSheet?
I did like ui.setupUi(this);;
QFont font("font: Arial", 12, QFont::PreferDefault);
ui.centralwidget->setFont(font);
Re: problem with Font changing
Quote:
Originally Posted by
mchara
Let's be more precise, does your constuctor looks like this?
// SomeClass constructor.
SomeClass::SomeClass(QWidget *aParent)
:QWidget(aParent)
{
ui.setupUi(this);
QFont font("Arial", 16);
ui.someWidget->setFont(font);
ui.someWidget2->setFont(font);
}
because termination on ui.someWidget->setFont(font); call it's surely because ui.someWidget is not initialized correctly.
and did you tried other way with styleSheet?
I did like ui.setupUi(this);;
QFont font("font: Arial", 12, QFont::PreferDefault);
ui.centralwidget->setFont(font);
still same problem. font is not getting changed.
Re: problem with Font changing
and what is centralWidget?
Re: problem with Font changing
Quote:
Originally Posted by
mchara
If you intend to change font in whole ui (not concrete widgets) u may use styleSheet.
The simplest way to use a styleSheet is to open ui in qtdesigner, and paste something like
It is possible to apply a Stylesheet to a single widget, or to a class of widgets, or to widgets with some certain properties:
Code:
// applies to the QLabel object with the objectName "certain-label"
color: blue;
font-weight: bold;
}
He could also call setStyleSheet on the widget to force a certain stylesheet for the widget after applying the other stylesheet on the application.
Stylesheets can much more than this ...
Re: problem with Font changing
Quote:
Originally Posted by
phillip_Qt
I did like ui.setupUi(this);
QFont font("font: Arial", 12, QFont::PreferDefault);
ui.centralwidget->setFont(font);
still same problem. font is not getting changed.
Perhaps the problem is the font name here.... "font: Arial" is not "Arial"
Vycke
Re: problem with Font changing
Quote:
Originally Posted by
vycke
Perhaps the problem is the font name here.... "font: Arial" is not "Arial"
Vycke
Sorry. i didnt understrand it. U mean instead of "font: Arial" i should write "Arial" only?:confused:
Re: problem with Font changing
Quote:
Originally Posted by
momesana
It is possible to apply a Stylesheet to a single widget, or to a class of widgets, or to widgets with some certain properties:
Code:
// applies to the QLabel object with the objectName "certain-label"
color: blue;
font-weight: bold;
}
He could also call setStyleSheet on the widget to force a certain stylesheet for the widget after applying the other stylesheet on the application.
Stylesheets can much more than this ...
Sure, but if i understood philip, he has several ui's in main window and want to change font only on several ui's so the best approach with stylesheets would be applying it on central widget of ui and let qt to propagate stylesheet to children.
I tried to suggest such solution to philip, but he didn't checked it i think...
So Philip, once again:
try with
ui.setupUi(this);
QString styleSheet = "QLabel{font: bold italic "Arial"; font-size:16}";
ui.centralwidget->setStyleSheet(styleSheet);
Re: problem with Font changing
Quote:
Originally Posted by
momesana
It is possible to apply a Stylesheet to a single widget, or to a class of widgets, or to widgets with some certain properties:
Code:
// applies to the QLabel object with the objectName "certain-label"
color: blue;
font-weight: bold;
}
He could also call setStyleSheet on the widget to force a certain stylesheet for the widget after applying the other stylesheet on the application.
Stylesheets can much more than this ...
Hi i tried like
QLabel#m_funktion1
{
font : Arial 12x;
}
But getting compilation error.
and also SetStyleSheet(QLabel#m_funktion1{font: Arial 12x}");
is not working.:(
Re: problem with Font changing
Why dont u just set the stylesheet to the label u want ??
my_label->setStyleSheet("font:Arial ; font-size: 12px");
Re: problem with Font changing
try with
ui.setupUi(this);
QString styleSheet = "QLabel{font: bold italic "Arial"; font-size:16}";
ui.centralwidget->setStyleSheet(styleSheet);
and you can also paste QLabel{font: bold italic "Arial"; font-size:16} in qt designer (styleSheet property of main widget) - tested it, works.
Try to use styleSheet as is and if it will work adjust it to you need - then you'll be sure that problem is with approach or with stylesheet itself.
Re: problem with Font changing
Quote:
Originally Posted by
mchara
Sure, but if i understood philip, he has several ui's in main window and want to change font only on several ui's so the best approach with stylesheets would be applying it on central widget of ui and let qt to propagate stylesheet to children.
I tried to suggest such solution to philip, but he didn't checked it i think...
So Philip, once again:
try with
ui.setupUi(this);
QString styleSheet = "QLabel{font: bold italic "Arial"; font-size:16}";
ui.centralwidget->setStyleSheet(styleSheet);
Thanx mchara very much. U are absolutly right. I've so many UIs. But i need to change only ceratin UI's font. Actually i'm chaning the colour by applyng qss file. there i "ve
QLabel
{
color : white;
font : Arial 12x;
}
But this one is not chaning the size.
Inside code as u told i"ve added
QString styleSheet ( "QLabel{font: bold italic; Arial; font-size:16}");
ui.centralwidget->setStyleSheet(styleSheet);
But this also not working. :(
Re: problem with Font changing
Quote:
Originally Posted by
aamer4yu
Why dont u just set the stylesheet to the label u want ??
my_label->setStyleSheet("font:Arial ; font-size: 12px");
Thanx aamer. I tried like so, still same problem.