Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Font properties and stylesheets in the Designer
Qt 6.12 LTS is out! See what's new in the release blog

Font properties and stylesheets in the Designer

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 2.5k 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.
  • B Offline
    B Offline
    Bert59
    wrote on last edited by
    #1

    I have some difficulties to understand the behavior of fonts and stylesheets in the Designer
    Here is an example

    I add a label and a Tab Widget
    a1749334-c28a-49c4-a5de-520ed305c24a-image.png

    Apply a vertical layout
    c62c5353-06f2-42dd-90f9-708eb82d715f-image.png

    Change text and properties of the top label
    4a317008-94a8-434f-9c2e-2cccedd31e7a-image.png

    Change Font size property of the Tab Widget to 12
    fadf453e-82b1-4209-bf80-c5e07096bb22-image.png

    Add a label to Tab 1 page and another below the Tab Widget
    69d35112-3495-4147-92f2-84f6bd458e5b-image.png

    My first question
    Why is the font size of the Label on the Tab Widget automatically changed to 12, the same size as for the text in the tabs
    290dade9-2ce0-44a9-88bc-8937e7a4ffb3-image.png
    and the label outside the Tab Widget keeps the default size
    58d9c218-c398-45e0-afa0-3fdc3f408a7b-image.png

    I was expecting that the label added to Tab 1 would also feature the default size of 8

    Now I add a few other Labels and a vertical layout to the Tab 1 page
    7ed69335-e59a-4caf-a21e-87aa8c16f93d-image.png

    I would like that the text in all labels in the Tab Widget are centered using Stylesheets
    From the documentation I know that {text-align: center} is not supported for labels, but I found a post on this forum explaining that the following is working
    QLabel {qproperty-alignment: AlignCenter;}

    So I right click on the tabs to open the Stylesheet window and add the above code
    72b74f81-f06a-45fd-994c-21c65a3485a2-image.png

    When I click Apply all the labels are centered as expected
    acb2e8f7-c392-48f2-b17e-6f67cf338209-image.png

    But when I close the Stylesheet window the font size of the labels is set to the default value 8.
    5407ba50-af4b-4485-92be-10c58cf291e7-image.png

    Why?

    Worse, when I run the application the labels are even not centered
    9ab05f10-fe00-487c-bab1-6d1720706e8d-image.png

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

      @Bert59 said in Font properties and stylesheets in the Designer:

      Change Font size property of the Tab Widget to 12

      Change Font size property of the Tab Widget to 12 <== for all contents in tab widget including all TextLabels.
      if you want to change the font of text labels, you can set different font size to them separately.
      QLabel has func setFont()

      Label {
          text: "Hello world"
          font.pixelSize: 22 <========
          font.italic: true
          color: "steelblue"
      }
      
      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
      • Unsolved