gnase
gnase

Reputation: 638

How to set border for message in QMessageBox?

I tried to set border for my message but it does not work. Can you guys point out where the problem is?

QMessageBox msg(this);
msg.setWindowModality(Qt::WindowModal);
msg.setWindowTitle(QLatin1String("Notice"));
msg.setTextFormat(Qt::RichText);
msg.setText("<html><head/><body><p>The reason of error is :</p><p><span style=\"border : 1px solid;\"><i> There is no data </i></span></p></body></html>");
msg.setStandardButtons(QMessageBox::Ok);
msg.setIcon(QMessageBox::Icon::Warning);
msg.exec();

This is the result, italic works but border does not work.

enter image description here

Upvotes: 0

Views: 1837

Answers (1)

thibsc
thibsc

Reputation: 4079

Check the Supported HTML Subset of Qt
Try to use border-color and border-style
You can also put the text "There is no data" in another QLabel and use

yourReasonLabel.setStyleSheet("border: 1px solid black;");

Or replace your span by a table and add css:

msg->setText("<html><head/><body>"
             "<p>The reason of error is :</p>"
             "<table style='border-style: solid; border-color: orange;border-width: 1px;'>"
             "<tr><td><i> There is no data </i></td></tr>"
             "</table></body></html>");

Upvotes: 1

Related Questions