How to Set Font to all Application
-
Hi,
in my application i have to allow user to choose Fontin mainwindows i call fontdialog()
now how i can set selected font to all form (and all contents of all form)?
i've tried with:
QFont V ("Verdana", 14); QApplication::setFont(V);
but don't works (menubar was not changed correctly for example)
i've also tried with:
ui->menuBar->setStyleSheet("QMenuBar { font-family:Verdana; font-size:12px;}" "QMenuBar::item { font-family:Verdana; font-size:12px;}" "QMenuBar::item:selected { font-family:Verdana; font-size:12px;}");
but don't works too (don't works for Action)
this solution works but i don't want to change font one by one (moreover don't works for Action):
bool ok; QFont Carattere = QFontDialog::getFont(&ok, this); if (ok) { V = Carattere; ui->menuBar->setFont(V); ui->menuFile->setFont(V); ui->menuOrdini->setFont(V); ui->menuModifica->setFont(V); ui->menuRegistra->setFont(V); ui->menuFornitore->setFont(V); ui->menuInserisci->setFont(V); ui->menuMagazzino->setFont(V); ui->menuAnagrafica->setFont(V); ui->menuProduzione->setFont(V); ui->menuda_Clienti->setFont(V); ui->menuCambia->setFont(V); } else { return; }
any ideas?
-
Did you try with QApplication setFont method ?
-
Did you try with QApplication setFont method ?
@dheerendra Yes, it's the first code i've posted up
-
Hi,
in my application i have to allow user to choose Fontin mainwindows i call fontdialog()
now how i can set selected font to all form (and all contents of all form)?
i've tried with:
QFont V ("Verdana", 14); QApplication::setFont(V);
but don't works (menubar was not changed correctly for example)
i've also tried with:
ui->menuBar->setStyleSheet("QMenuBar { font-family:Verdana; font-size:12px;}" "QMenuBar::item { font-family:Verdana; font-size:12px;}" "QMenuBar::item:selected { font-family:Verdana; font-size:12px;}");
but don't works too (don't works for Action)
this solution works but i don't want to change font one by one (moreover don't works for Action):
bool ok; QFont Carattere = QFontDialog::getFont(&ok, this); if (ok) { V = Carattere; ui->menuBar->setFont(V); ui->menuFile->setFont(V); ui->menuOrdini->setFont(V); ui->menuModifica->setFont(V); ui->menuRegistra->setFont(V); ui->menuFornitore->setFont(V); ui->menuInserisci->setFont(V); ui->menuMagazzino->setFont(V); ui->menuAnagrafica->setFont(V); ui->menuProduzione->setFont(V); ui->menuda_Clienti->setFont(V); ui->menuCambia->setFont(V); } else { return; }
any ideas?
@TheCipo76
generally fonts propagate down to descendant child widgets (see this)Are you setting fonts via stylesheet in your application?
-
@TheCipo76
generally fonts propagate down to descendant child widgets (see this)Are you setting fonts via stylesheet in your application?
@raven-worx No i don't have used stylesheet
i need to allow font selection because my application works both on os x than windows..
i have already read this article today ;)
-
with a fontdialog i can set the QApplication::font
at the moment i have to set the QApplication::font to every widget one by one eg:
ui->label->setFont(QApplication::Font());
and when i open a dialog i have to do the same operation to all form widget..
i'm looking to something faster / easier
-
with a fontdialog i can set the QApplication::font
at the moment i have to set the QApplication::font to every widget one by one eg:
ui->label->setFont(QApplication::Font());
and when i open a dialog i have to do the same operation to all form widget..
i'm looking to something faster / easier
@TheCipo76
since you read the article, you are aware that setting the font explicitly (manually or via stylesheet) prevents font propagation (Qt::WA_SetFont
attribute)?! -
@TheCipo76
since you read the article, you are aware that setting the font explicitly (manually or via stylesheet) prevents font propagation (Qt::WA_SetFont
attribute)?!@raven-worx yes.. i'm fix it with this:
void MainWindow::updateAllWidgets() { foreach (QWidget *widget, QApplication::allWidgets()) { widget->setFont(QApplication::font()); widget->update(); } }
But don't works on Menu Action