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

QFontDialog::getFont() doesn't use correct font style

Scheduled Pinned Locked Moved Unsolved General and Desktop
29 Posts 3 Posters 10.1k Views
  • 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 pbe
    16 Jul 2016, 09:02

    On 2nd glance, maybe it's really better to reply here.
    So here comes by better example:

    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!

    K Offline
    K Offline
    kshegunov
    Moderators
    wrote on 17 Jul 2016, 20:50 last edited by
    #13

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

    Read and abide by the Qt Code of Conduct

    1 Reply Last reply
    1
    • P Offline
      P Offline
      pbe
      wrote on 18 Jul 2016, 05:12 last edited by
      #14

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

      K 1 Reply Last reply 19 Jul 2016, 18:22
      0
      • P pbe
        18 Jul 2016, 05:12

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

        K Offline
        K Offline
        kshegunov
        Moderators
        wrote on 19 Jul 2016, 18:22 last edited by kshegunov
        #15

        @pbe said:

        Do you have any ideas to get around this?

        Sadly, no. The bug seems inherent to the QFontDialog class when the QFont'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.

        Read and abide by the Qt Code of Conduct

        1 Reply Last reply
        2
        • P Offline
          P Offline
          pbe
          wrote on 19 Jul 2016, 18:23 last edited by
          #16

          @kshegunov, thank you very much! You are my hero!

          K 1 Reply Last reply 24 Jul 2016, 13:57
          0
          • P pbe
            19 Jul 2016, 18:23

            @kshegunov, thank you very much! You are my hero!

            K Offline
            K Offline
            kshegunov
            Moderators
            wrote on 24 Jul 2016, 13:57 last edited by
            #17

            @pbe
            I have a bug fix and I'll try to submit it this evening (I've been working in the dev branch, so some git magic is needed).

            Kind regards.

            Read and abide by the Qt Code of Conduct

            P 1 Reply Last reply 24 Jul 2016, 16:40
            1
            • K kshegunov
              24 Jul 2016, 13:57

              @pbe
              I have a bug fix and I'll try to submit it this evening (I've been working in the dev branch, so some git magic is needed).

              Kind regards.

              P Offline
              P Offline
              pbe
              wrote on 24 Jul 2016, 16:40 last edited by
              #18

              @kshegunov, really? That's wonderful! I can't wait to see it!

              K 1 Reply Last reply 24 Jul 2016, 18:45
              0
              • P pbe
                24 Jul 2016, 16:40

                @kshegunov, really? That's wonderful! I can't wait to see it!

                K Offline
                K Offline
                kshegunov
                Moderators
                wrote on 24 Jul 2016, 18:45 last edited by kshegunov
                #19

                @pbe
                https://codereview.qt-project.org/#/c/165958/

                We'll see if it gets approved.

                Read and abide by the Qt Code of Conduct

                1 Reply Last reply
                1
                • P Offline
                  P Offline
                  pbe
                  wrote on 24 Jul 2016, 19:48 last edited by
                  #20

                  Thanks a lot, I will watch that request!

                  K 1 Reply Last reply 25 Jul 2016, 12:30
                  0
                  • P pbe
                    24 Jul 2016, 19:48

                    Thanks a lot, I will watch that request!

                    K Offline
                    K Offline
                    kshegunov
                    Moderators
                    wrote on 25 Jul 2016, 12:30 last edited by
                    #21

                    @pbe
                    There's something else, while investigating your bug I stumbled upon this one ... which you may actually encounter, although it's somewhat unrelated to your problem with the dialog.

                    Read and abide by the Qt Code of Conduct

                    1 Reply Last reply
                    0
                    • P Offline
                      P Offline
                      pbe
                      wrote on 25 Jul 2016, 13:06 last edited by
                      #22

                      @kshegunov, that really is what I'm encountering... So actually two bugs are triggered here...

                      1 Reply Last reply
                      0
                      • P Offline
                        P Offline
                        pbe
                        wrote on 25 Jul 2016, 13:09 last edited by
                        #23

                        Really thanks a lot for your help!

                        K 1 Reply Last reply 3 Aug 2016, 15:28
                        0
                        • P pbe
                          25 Jul 2016, 13:09

                          Really thanks a lot for your help!

                          K Offline
                          K Offline
                          kshegunov
                          Moderators
                          wrote on 3 Aug 2016, 15:28 last edited by
                          #24

                          @pbe
                          QTBUG-54936's been merged and the patch will be incorporated in Qt 5.8

                          Kind regards.

                          Read and abide by the Qt Code of Conduct

                          1 Reply Last reply
                          0
                          • P Offline
                            P Offline
                            pbe
                            wrote on 3 Aug 2016, 20:17 last edited by
                            #25

                            @kshegunov, great news! Thanks a lot!

                            K 1 Reply Last reply 3 Aug 2016, 22:04
                            0
                            • P pbe
                              3 Aug 2016, 20:17

                              @kshegunov, great news! Thanks a lot!

                              K Offline
                              K Offline
                              kshegunov
                              Moderators
                              wrote on 3 Aug 2016, 22:04 last edited by
                              #26

                              @pbe
                              My pleasure. The dialog bug is low(er) priority and it may take some time for the proposed patch to get reviewed.

                              Kind regards.

                              Read and abide by the Qt Code of Conduct

                              P 1 Reply Last reply 4 Aug 2016, 04:40
                              0
                              • K kshegunov
                                3 Aug 2016, 22:04

                                @pbe
                                My pleasure. The dialog bug is low(er) priority and it may take some time for the proposed patch to get reviewed.

                                Kind regards.

                                P Offline
                                P Offline
                                pbe
                                wrote on 4 Aug 2016, 04:40 last edited by
                                #27

                                @kshegunov I wonder if it will get fixed at all...

                                K 1 Reply Last reply 4 Aug 2016, 11:09
                                0
                                • P pbe
                                  4 Aug 2016, 04:40

                                  @kshegunov I wonder if it will get fixed at all...

                                  K Offline
                                  K Offline
                                  kshegunov
                                  Moderators
                                  wrote on 4 Aug 2016, 11:09 last edited by
                                  #28

                                  @pbe
                                  It's going to, it'ill just take some time. Now things a bit slow because most people are on vacation.

                                  Read and abide by the Qt Code of Conduct

                                  P 1 Reply Last reply 4 Aug 2016, 12:14
                                  0
                                  • K kshegunov
                                    4 Aug 2016, 11:09

                                    @pbe
                                    It's going to, it'ill just take some time. Now things a bit slow because most people are on vacation.

                                    P Offline
                                    P Offline
                                    pbe
                                    wrote on 4 Aug 2016, 12:14 last edited by
                                    #29

                                    @kshegunov, humans... :)

                                    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