Making QMessageBox InformativeText Bold and increase font size

6.7k views Asked by At

In my qt C++ gui application, I have a QMessageBox with 3 buttons and some standard functionality. I want to decorate all these with stylesheets and fonts and what not.

I am successfully able to do the following -

i. Set MessageBox background.

ii. Set Button background.

void MainWindow::on_pushButton_clicked()
{
    QMessageBox msgbox;
    msgbox.setInformativeText("YOLO");
    msgbox.setStandardButtons(QMessageBox::Ok|QMessageBox::No|QMessageBox::Cancel);
    msgbox.setWindowFlags(Qt::FramelessWindowHint);
    msgbox.setStyleSheet("QMessageBox { background-image: url(:/res/bk.jpg) }");
    msgbox.button(QMessageBox::Ok)->setStyleSheet("QPushButton { background-image: url(:/res/green_bk.jpg) }");
    msgbox.button(QMessageBox::No)->setStyleSheet("QPushButton { background-image: url(:/res/red_bk.jpeg) }");
    msgbox.exec();
}

But I am stuck on how to set a font (type and size) to the InformativeText field, and also how to make it Bold. I have referred to the InformativeText Properties but I am unable to sort things out. Any ideas on how to achieve this ? Thanks.

As an added query, can I change the fonts (type and size) of buttons as well and set Bold Italics etc ?

EDIT

I did the following changes to my code, and the results are baffling,

QFont font;
font.setBold(true);
msgbox.setFont(font);

After doing this, my informationText has become bold, my cancel button has become bold. But the Ok and No buttons are normal (non-bold). If I remove the setStylesheets for the two buttons, only then are they becoming bold (which is useless, since I want background images).

Any ideas to have a synergy in all these ???

1

There are 1 answers

0
developer0hye On

I found solution for your problems.

QMessageBox msg(QMessageBox::Information,"Hey", "Dude", QMessageBox::Ok);

QFont font;
font.setBold(true);
msg.setFont(font);

msg.button(QMessageBox::Ok)->setFont(font);

msg.exec();