I was trying to build a simple application with a QComboBox
and a QPushButton
. The idea is to populate the QComboBox
with a list of all available fonts in the system. When the user selects a font and presses the QPushButton
then a QMessageBox
appears with the font selected. Now how to do it?
The solution is using the setFont()
method of the QMessageBox
QMessageBox *msg = new QMessageBox(QMessageBox::Information, "Message with font",
"This message is in font: " + ui->comboBox->currentText(),
QMessageBox::Ok | QMessageBox::Cancel, this);
QFont font = QFont(ui->comboBox->currentText());
msg->setFont(font);
msg->exec();
Where combobox
is QComboBox
used.