QFontDialog::getFont() doesn't use correct font style
-
@pbe
Hi,
There's a bug - QTBUG-52741 that appears to be what you're describing. I also run your example through the debugger after I was able to reproduce (Qt 5.7) and the problem is indeed in the dialog, here.The dialog matches the family only, and when it calls
setCurrentItem
it selects the very first item in the model (which has the default style), which in turn will overwrite the member that holds the style and you get what you described. If you use the font object directly you won't get the bug, i.e.:QFont font = QFontDialog::getFont(&ok); if (ok) { // ... QFont font2 = QFontDialog::getFont(&ok, font, this); //< Works correctly, no bug // ... }
Kind regards.
-
@kshegunov, I already found that bug and was wondering if that's what's affecting QOwnNotes. Thank you for making that clear!
Yes, you are right. If you use the font directly it works, but it doesn't work with
font2.fromString(font.toString());
that is needed to store and load it to/from the settings. Do you have any ideas to get around this? -
@pbe said:
Do you have any ideas to get around this?
Sadly, no. The bug seems inherent to the
QFontDialog
class when theQFont
's internal identifier isn't set (i.e. when the dialog needs to go and query about the font by its attributes). If I get some more time in the coming days, I'll try to run it again and hopefully will have something better.Kind regards.
-
@kshegunov, thank you very much! You are my hero!
-
@pbe
https://codereview.qt-project.org/#/c/165958/We'll see if it gets approved.
-
@kshegunov, that really is what I'm encountering... So actually two bugs are triggered here...
-
@pbe
QTBUG-54936's been merged and the patch will be incorporated in Qt 5.8Kind regards.
-
@kshegunov, great news! Thanks a lot!