PDA

View Full Version : How to change the font and color of entire Qt application at runtime?



AviMittal
5th August 2009, 07:20
Hi
I am building a desktop application using Qt4. I have multiple forms and multiple types of widgets on those forms. Now i have a requirement to allow the user to change the color and font of entire application at run-time ( without restarting the application). I am really not sure how to achieve this. please suggest.

wagmare
5th August 2009, 07:23
void QApplication::setFont ( const QFont & font, const char * className = 0 ) [static]

set to the qpplication of your font .. try this one ... but not sure ..

AviMittal
5th August 2009, 07:35
hey it didnt worked...what i did is..i took one ui..and added one lable and pushbutton to it.
On click of pushbutton i activated a slot "test()" in which i called QApplication::setFont().
but it only chnages the color of pushButton not the entire form.

my code is here:

ColorMode::ColorMode(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
connect(ui.pushButton, SIGNAL(clicked()),this, SLOT(test()));
}

void ColorMode::test()
{
QFont font("Times", 15, QFont::Bold);
QApplication::setFont(font);
}

any suggestions???

yogeshgokul
5th August 2009, 08:03
Can you check that you slot is being called or not. Because this should work.;);):cool:

AviMittal
5th August 2009, 08:10
hey..it checked..the slot is getting called for sure but its only changing the font of pushButton not for the label.

yogeshgokul
5th August 2009, 08:16
Can you add more test buttons to your UI. So we can find out whats wrong with QLabel. Why only label's font is not getting changed.

numbat
5th August 2009, 11:40
Assumably, the label is not being updated because it is not being redrawn. Try, the updateAllWidgets function shown at QApplication::allWidgets