1
votes

The Informative Text of a QMessageBox can be formatted as rich text, and I understood that the html <font></font> tag was allowable for rich text in this context. However, the size attribute does not seem to work as expected. When used, the size of the QMessageBox informative text is larger than normal, but the specific value seemingly has no effect (even though the attribute color, and the <i> & <b> tags seem to work as expected). Here's the output:

<code>QMessageBox</code> seems insensitive to font tag's size attribute

Is there a way to specify font sizes in html (or rtf) markup in the Informative Text of a QMessageBox?

void MainWindow::about()
{
    QMessageBox msgAbout;
    msgAbout.setInformativeText("<span style='text-align: center'><p><b><font size = 20 color = red><i>Supposedly</i> set in 30pt font</font><p><font size = 20 color = blue><i>Rumoredly</i> set in 20pt font</font><p><font size = 10 color = green><i>Putatively</i> set in 10pt font</font><p>Proud not to use the &lt;font&gt; tag!</span><p>");
    msgAbout.setStandardButtons(QMessageBox::Ok);
    msgAbout.setDefaultButton(QMessageBox::Ok);
    msgAbout.exec();
}

macOS 10.13.3
Qt Creator 4.5 based on Qt 5.10.0 (Clang 7.0 (Apple), 64 bit)

1

1 Answers

3
votes

You have to use : instead of =:. You have to place font-size within the style attribute of the relevant <p> tag. And you have to specify the font size units (e.g., 12pt).

QMessageBox msgAbout;
msgAbout.setInformativeText("<span style='text-align: center'><p style='font-size: 30pt; color: red'><b><i>Supposedly</i> set in 30pt font</p><p style='font-size: 20pt; color: blue'><i>Rumoredly</i> set in 20pt font</p><p style='font-size: 10pt; color: green'><i>Putatively</i> set in 10pt font</p><p>Proud not to specify font-size attributes!</span><p>");
msgAbout.setStandardButtons(QMessageBox::Ok);
msgAbout.setDefaultButton(QMessageBox::Ok);
msgAbout.exec();

enter image description here