I have run into the same problem using Qt 5.15.2.
Setting fontFamily(name) on QTextEdit will not change the font name, but append it as a secondary name, causing QTextEdit to not show the correct font, since it uses the first font name.
This does not happen if QTextEdit is set with a plain text, but setHtml(ht) will cause the problem.
The following code example shows the problem without using UI.
QTextEdit te;
// Start by setting a text using Arial
te.setFontFamily("Arial");
te.setText("ABC");
// The html output shows ... font-family:'Arial'
QString html = te.toHtml();
qDebug() << "html 1" << html;
// Then select all text and change font to Calibri
QTextCursor crs = te.textCursor();
crs.movePosition(QTextCursor::Start);
crs.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
te.setTextCursor(crs);
te.setFontFamily("Calibri");
// The html output is still good with ... font-family:'Calibri'
html = te.toHtml();
qDebug() << "html 2" << html;
// Change the font back to Arial
te.setFontFamily("Arial");
// The html output is still good with ... font-family:'Arial'
html = te.toHtml();
qDebug() << "html 3" << html;
// Now set the text using the good html with Arial
te.setHtml(html);
// Again select all text and set the font to Calibri
crs = te.textCursor();
crs.movePosition(QTextCursor::Start);
crs.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
te.setTextCursor(crs);
te.setFontFamily("Calibri");
// Now the html output is bad with ... font-family:'Arial','Calibri'
html = te.toHtml();
qDebug() << "html 4" << html;
The output from above code:
html 1 "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">\n<html><head><meta name="qrichtext" content="1" /><style type="text/css">\np, li { white-space: pre-wrap; }\n</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">\n<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Arial';">ABC</span></p></body></html>"
html 2 "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">\n<html><head><meta name="qrichtext" content="1" /><style type="text/css">\np, li { white-space: pre-wrap; }\n</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">\n<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Calibri';">ABC</span></p></body></html>"
html 3 "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">\n<html><head><meta name="qrichtext" content="1" /><style type="text/css">\np, li { white-space: pre-wrap; }\n</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">\n<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Arial';">ABC</span></p></body></html>"
html 4 "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">\n<html><head><meta name="qrichtext" content="1" /><style type="text/css">\np, li { white-space: pre-wrap; }\n</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">\n<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Arial','Calibri';">ABC</span></p></body></html>"
where the last line with font-family:'Arial','Calibri' is not as expected.
It should only say Calibri to work correctly.
Kind regards
Søren