如何在QMessageBox中为消息设置边框?
问题描述:
我试图为我的消息设置边框,但它不起作用。你们能指出问题出在哪里吗?如何在QMessageBox中为消息设置边框?
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();
这是结果,斜体的作品,但边界不起作用。
答
检查的Qt
的Supported HTML Subset的尝试使用border-color
和border-style
您还可以通过把文本"There is no data"
在另一个QLabel和使用
yourReasonLabel.setStyleSheet("border: 1px solid black;");
或替换span
a table
并添加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>");
谢谢。我试图使用'border-style',但它不起作用。而且我不知道如何为边框设置像素,没有'border-width'。 – gnase
是的,我也考虑过这个问题,但我仍然不知道如何在msg中添加标签 – gnase
@gnase,您可以继承QDialog''来创建自己的''MessageBox' ' –