Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
5.13.2, 5.14.2, 5.15.0
-
None
Description
When QTextEdit is set to an HTML string generated previously by QTextEdit, setFontFamily() ceases to work.
Steps to reproduce
- Start a new rich text document with a QTextEdit. Note that QTextEdit::setFontFamily will work as expected.
- Export its data using QTextEdit::toHtml()
- Re-import that data into QTextEdit using QTextEdit::setHtml()
- From here onwards, QTextEdit::setFontFamily() will appear to do nothing and seem to have no effect
- Looking at the HTML (retrieved from QTextEdit::toHtml() again), it's clear that the font family was appended as a backup family instead of replacing the family, and will therefore never be used as long as the primary family exists:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><style type="text/css"> p, li { white-space: pre-wrap; } </style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> <p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:144pt;">Sample </span><span style=" font-family:'MS Shell Dlg 2','Monotype Corsiva'; font-size:144pt;">Text</span></p></body></html>
Note: "font-family:'MS Shell Dlg 2','Monotype Corsiva';" towards the end
This bug can be seen on Qt's own "Text Edit" example program. When starting the program, changing the font family will work as expected. But upon saving it as HTML and re-loading the file, the font family will no longer change (and checking the resulting HTML will show the new font family appended rather than replaced as in the above example).
This behavior appears to occur on 5.13.2, 5.14.2, and 5.15.0. It does NOT occur on 5.12.8, so presumably it was introduced somewhere around 5.13.x.