Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QFontDialog::getFont() doesn't use correct font style when font of the font parameter use toString() and fromString()
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 806 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pbe
    wrote on last edited by pbe
    #1

    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

    kshegunovK 1 Reply Last reply
    0
    • P pbe

      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

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by kshegunov
      #2

      @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.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved