html - QMessageBox中如何给消息设置边框?

标签 html css qt 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();

这是结果,斜体有效但边框无效。

enter image description here

最佳答案

检查 Supported HTML Subset Qt的
尝试使用 border-colorborder-style
您还可以将文本 "There is no data" 放在另一个 QLabel 中并使用

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

或者用table替换你的span并添加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>");

关于html - QMessageBox中如何给消息设置边框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43973982/

相关文章:

html - 不听话的师长! ( float 不正确)

javascript - 如何在 jquery(或 javascript)中选择相邻元素

css - polymer - 单击时禁用灰色背景

css - 如何为 Twitter 的 Bootstrap 帮助 block 添加边距?

c++ - Qt:使用信号和槽从另一个类调用 MainWindow::Ui

php - 在 php 中将 .doc 转换为 html

html - 顶部和底部的盒子阴影

html - 如何使用 CSS 使固定的 HTML 标题水平滚动?

c++ - Qt的替代品?

c++ - QSet:qHash 和自定义类错误