0

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 ???

RicoRicochet
  • 2,249
  • 9
  • 28
  • 53
  • 1
    I shooting guesses: 1.- See about setTextFormat of QMessagebox; 2.- Use html tags in informativeText; 3.- Make your own – Joel Jun 19 '15 at 03:51
  • thanx for the response, i am not confident about the html thingey (point 2). and I cant make own (point 3). am a total noob. I am looking for something inline to your point 1. But unable to find any code segment.. I am really sad because of low rate of responses. Maybe qt is not much preferred now-a-days. – RicoRicochet Jun 19 '15 at 06:10
  • Making your own is like making a dialog in designer, there are tons of examples and the web. About how to use ui files in your code. – Joel Jun 19 '15 at 14:42

1 Answers1

1

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();
developer0hye
  • 183
  • 3
  • 8