Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Font size for custom Object type based on standard font size
Forum Updated to NodeBB v4.3 + New Features

Font size for custom Object type based on standard font size

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 874 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.
  • H Offline
    H Offline
    hugOrtega
    wrote on 7 Oct 2016, 05:38 last edited by
    #1

    Hello everybody,

    I'm working in an application which needs labels with font size bigger that standard Label element. Since I'm working with QtQuick.Controls 2, all font sizes are computed according to platform and screen resolutions, I don't have to worry about that and works fantastic (at least for platforms I need for the project).

    My problem is about the approach to specify the font size for those bigger labels. I can't use a fixed value for font.pointSize or font.pixelSize because platform screen resolution issues. If I use font.pointSize with any fixed value, the "physical" size of the text varies on different devices/screen resolutions (Desktop, Tablet)

    For example, I need a label for some kind of alerts, 50% bigger than a standard Label element. I'm using something like this:

    // AlertLabel.qml
    Label {
        font.pointSize: font.pointSize * 1.5
        font.bold: true
        color: "red"
    }
    

    and works fine: the AlertLabel is displayed 50% bigger than a standard Label and is screen resolution cross-platform... but there is a warning (an expected one) I don't like:

    QML Label: Binding loop detected for property "font.pointSize"
    

    Apparently, this is something which QML supports anyway for this case and there are no other problems, but I don't know if this will be a issue in the future (performance?), and also don't like the warning :D ... or maybe the approach is good and I just have to ignore the warning.

    I searched in documentation and forums about something I can use to avoid the loop (e.g. font.pointSize : Qt.ComputedFontSizeForThisPlatform * 1.5 ) or even with C++.

    Any hint will be appreciated. Thanks!

    Hugo

    1 Reply Last reply
    0
    • P Offline
      P Offline
      p3c0
      Moderators
      wrote on 7 Oct 2016, 05:53 last edited by
      #2

      @hugOrtega Try:

      Label {
         ...
         Component.onCompleted: {
                font.pointSize = font.pointSize * 1.5
         }
      }
      

      157

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hugOrtega
        wrote on 7 Oct 2016, 06:23 last edited by
        #3

        You're right, this works very well (and give me new perspective about the QML intrinsic flow)

        Thanks a lot.

        Hugo

        1 Reply Last reply
        0

        1/3

        7 Oct 2016, 05:38

        • Login

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