QFontDialog::getFont() doesn't use correct font style when font of the font parameter use toString() and fromString()



  • I have a problem with QFontDialog::getFont().

    QFontDialog::getFont() doesn't use the correct font style when the font of the font parameter uses toString() and fromString().
    It always uses the first font style in the list instead of the style (normal) and weight (regular) of the QFont parameter.
    I made an example:

    bool ok;
    
    // select a font where `Regular` is not the first item in the `Font
    // style` selector (e.g. `Noto Sans`) and select `Regular`
    QFont font = QFontDialog::getFont(&ok);
    if (ok) {
        // looks like `QFont( "Noto Sans,11,-1,5,50,0,0,0,0,0" )`
        qDebug() << "'font': " << font;
    
        QFont font2;
        // I originally store the font to the settings and load it again, but
        // that's not even needed to reproduce this problem
        font2.fromString(font.toString());
        // still looks like `QFont( "Noto Sans,11,-1,5,50,0,0,0,0,0" )`
        qDebug() << "'font2': " << font2;
    
        // now `Bold Italic` is selected, because it's the first item
        QFont font3 = QFontDialog::getFont(&ok, font2, this);
    
        if (ok) {
            // would now look like `QFont( "Noto Sans,11,-1,5,75,1,0,0,0,0" )`
            qDebug() << "'font3': " << font3;
        }
    }
    

    I was testing under:

    Platform: linux
    Operating System: KDE neon User Edition 5.7
    Build architecture: x86_64
    Current architecture: x86_64
    Qt Version (build): 5.7.0
    Qt Version (runtime): 5.7.0

    (The problem was initially reported by a user of QOwnNotes at https://github.com/pbek/QOwnNotes/issues/239.)

    Am I doing something wrong?
    Thanks a lot for your help!

    PS: Here a screenshot with Norasi

    dialog


  • Qt Champions 2016

    @pbe
    Hi,
    Please don't open a new topic for an actively discussed question. It's not productive and honestly it's a bit insulting for the people who originally tried to help. If you want to add some information either post it in the last topic, or edit the original post. This one shall be closed as a duplicate.

    Kind regards.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.