Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-69499

QFont::setStyleName doesn't work on Windows

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.10.1, 5.11.1
    • GUI: Font handling
    • None
    • Windows 10
    • Windows

    Description

      Unless I'm doing something terribly wrong, QFont::setStyleName doesn't work on Windows. 

      I'm testing it with font styles listed by QFontDatabase, and in my simplified test rendering directly to a QLabel. I've also tried dozens of other font variant/style names, they all effectively render in the parent font family.

      #include <QApplication>
      #include <QDebug>
      #include <QFontDatabase>
      #include <QLabel>
      #include <QMainWindow>
      
      int main(int argc, char *argv[])
      {
      QApplication a(argc, argv);
      QMainWindow w;
      
      QFont font("Arial", 244.0);
      font.setStyleName("Bold Italic");
      
      QFontDatabase db;
      qDebug() << db.styles(font.family());
      
      QLabel* label = new QLabel("Text");
      label->setFont(font);
      
      w.setCentralWidget(label);
      w.show();
      
      return a.exec();
      }
      

      In the attached screenshot you can see the font rendered is just regular Arial rather than the Bold Italic variant which QFontDatabase tells me should exist.

      There are hints in the documentation about the "lack of full cross platform support" for some properties of QFont, but if this is 100% not supported and not likely to be, it would be great to be more explicit (with a note on the method itself for example).

      Attachments

        1. Capture.PNG
          70 kB
          Daniel Wood
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            esabraha Eskil Abrahamsen Blomfeldt
            danielgwood Daniel Wood
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes