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. Convert QFont styleName to stylesheet
Forum Updated to NodeBB v4.3 + New Features

Convert QFont styleName to stylesheet

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 592 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.
  • A Offline
    A Offline
    AlexNevskiy
    wrote on last edited by
    #1

    Hello, guys! I need some help.

    Imagine, I have a widget form and display values on it, and I want the values' labels to be displayed with some other font than the other text labels. So I give them a css class name for example "Value" and want to set some font through the stylesheet (QLabel.Value {...}).
    I try to set up QLabel's font through the Qt Designers stylesheet dialog, but if I select for example font Lato with style Medium, Designer converts it to string:

    font: 57 12pt "Lato";
    

    and the label shows very thin font which is absolutely not Medium style.

    If I try another font Gotham with style Book, the Designer doesn't see it at all and outputs:

      font: 12pt "Gotham".
    

    So the questions are:

    1. Do stylesheets support font style names?
    2. If no, which qt way I can assign required font to all of the labels (or widgets) of the same type?

    P.S. I'm using Windows 10, Qt 15.2 MinGW.

    1 Reply Last reply
    0
    • JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by JoeCFD
      #2

      https://doc.qt.io/qt-5/qfont.html#Style-enum
      QFont::Weight ==> font.setWeight( Qt::Medium )
      QFont font( QString( "Lato" ), 12 );
      font.setWeight( Qt::Medium );

      True: can not find style book

      A 1 Reply Last reply
      0
      • JoeCFDJ JoeCFD

        https://doc.qt.io/qt-5/qfont.html#Style-enum
        QFont::Weight ==> font.setWeight( Qt::Medium )
        QFont font( QString( "Lato" ), 12 );
        font.setWeight( Qt::Medium );

        True: can not find style book

        A Offline
        A Offline
        AlexNevskiy
        wrote on last edited by
        #3

        @JoeCFD First of all, this way you set font through the API, but I need to set one through the stylesheet cause I need font to be set to the whole class of widgets.
        BTW, style name have to be set by function setStyleName, for example:

        font.setStyleName("Book");
        

        and it works ok.

        JoeCFDJ 1 Reply Last reply
        0
        • A AlexNevskiy

          @JoeCFD First of all, this way you set font through the API, but I need to set one through the stylesheet cause I need font to be set to the whole class of widgets.
          BTW, style name have to be set by function setStyleName, for example:

          font.setStyleName("Book");
          

          and it works ok.

          JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by JoeCFD
          #4

          @AlexNevskiy Is not it same to set font to their parent widget?

          A 1 Reply Last reply
          0
          • JoeCFDJ JoeCFD

            @AlexNevskiy Is not it same to set font to their parent widget?

            A Offline
            A Offline
            AlexNevskiy
            wrote on last edited by AlexNevskiy
            #5

            @JoeCFD If I set font to the parent widget it will apply to all the child widgets and not to the certain class of widgets.

            JoeCFDJ 1 Reply Last reply
            0
            • A AlexNevskiy

              @JoeCFD If I set font to the parent widget it will apply to all the child widgets and not to the certain class of widgets.

              JoeCFDJ Offline
              JoeCFDJ Offline
              JoeCFD
              wrote on last edited by
              #6

              @AlexNevskiy It is true. And it is the same with stylesheet.

              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