Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
6.2.0
-
None
Description
When you set an invalid font on a QFontComboBox, the first entry in the list of fonts will be selected by default, and the currentFont() will reflect this.
But if the first entry is already selected when you do this, we will update the currentFont to match the invalid font and then skip all subsequent updates because the index has not actually changed. So you end up with currentFont() returning the invalid request instead.
This can be reproduced with the following code:
#include <QtGui> #include <QtWidgets> int main(int argc, char *argv[]) { QApplication a(argc, argv); QFontComboBox box; box.setCurrentFont(QFont("Invalid Font")); qDebug() << box.currentFont().family(); box.setCurrentFont(QFont("Another Invalid Font")); qDebug() << box.currentFont().family(); return 0; }
The example prints out the following on my Windows machine:
"Arial" "Another Invalid Font"
So the first time and invalid font is requested, we select the first valid font instead (Arial). The next time, currentFont() returns the invalid font family instead (this does not match the text in the editor at this point).
Note: If the first entry happens to be the default (on macOS for instance, since the default font is not available in the list) or if you manually select index 0, the bug will occur on the first call to setCurrentFont() instead.
Attachments
Issue Links
- resulted from
-
QTBUG-97995 Error deserializing QFont (from 5.15 to 6.2)
- Closed