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. aligning fonts of differing sizes
Forum Updated to NodeBB v4.3 + New Features

aligning fonts of differing sizes

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 503 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.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by
    #1

    Hi all -

    I'm trying to modify the very nice CircularSlider code found in the marketplace. Specifically, I need the center of the slider to contain text of multiple font sizes, aligned at their bottom. (This is going to be slightly complicated by the fact that I need to rotate the slider 180 degrees, but I'll deal with that later.)

    Here's a snippet of my code:

    CircularSlider {
        id: circularSlider
        anchors.centerIn: parent
        width: 200
        height: 200
        rotation: 0//180
    
        // the left/right anchors are backwards from
        // what one might expect, because we've rotated
        // the CircularSlider 180 degrees.
        CLabel {
            anchors {
                right: parent.horizontalCenter
                bottom: parent.verticalCenter
            }
            text: "10"//Number(circularSlider.value).toFixed()
            font.pixelSize: 24
            font.weight: Font.Bold
            rotation: -circularSlider.rotation
        }
        CLabel {
            anchors {
                left: parent.horizontalCenter
                bottom: parent.verticalCenter
            }
            text: "gpm"
            rotation: -circularSlider.rotation
        }
    }
    

    (You can replace the "CircularSlider" with an ordinary rectangle object if you want to try the code yourself.)
    And here's what I'm getting:

    textalign.PNG

    So, I'm curious as to why the two text objects don't line up. Also, if there's a better way to handle this in general, I'm open to any and all suggestions.

    Thanks...

    1 Reply Last reply
    0
    • MarkkyboyM Offline
      MarkkyboyM Offline
      Markkyboy
      wrote on last edited by Markkyboy
      #2
          CircularSlider {
              id: circularSlider
              anchors.centerIn: parent
              width: 200
              height: 200
              rotation: 0//180
      
              Row {
                  spacing: 10
      
                  Label {
                      id: num
                      text: "10"//Number(circularSlider.value).toFixed()
                      font.pixelSize: 72
                      font.weight: Font.Bold
                  }
                  Label {
                      text: "gpm"
                      anchors.verticalCenter: num.verticalCenter
                      anchors.bottom: num.baseline
                  }
              }
          }
      

      Don't just sit there standing around, pick up a shovel and sweep up!

      I live by the sea, not in it.

      mzimmersM 1 Reply Last reply
      1
      • MarkkyboyM Markkyboy
            CircularSlider {
                id: circularSlider
                anchors.centerIn: parent
                width: 200
                height: 200
                rotation: 0//180
        
                Row {
                    spacing: 10
        
                    Label {
                        id: num
                        text: "10"//Number(circularSlider.value).toFixed()
                        font.pixelSize: 72
                        font.weight: Font.Bold
                    }
                    Label {
                        text: "gpm"
                        anchors.verticalCenter: num.verticalCenter
                        anchors.bottom: num.baseline
                    }
                }
            }
        
        mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on last edited by mzimmers
        #3

        @Markkyboy thank you; this is a very good start.

        Now, I need to contend with the fact that I have to rotate the slider 180 degrees. Doing so results in this:
        slider.PNG
        As you can see, there are two problems with this:

        1. the text fields are backwards ("gpm" comes before "10")
        2. they're aligned at the top, not the bottom.

        Would the correct solution be to enclose this in an invisible rectangle, and make the Labels peers of the slider instead of children? Or is there a more elegant way to fix this?

        Thanks...

        EDIT: I added the following line to both Labels to get the text right side up:

        rotation: -circularSlider.rotation
        
        mzimmersM 1 Reply Last reply
        0
        • mzimmersM mzimmers

          @Markkyboy thank you; this is a very good start.

          Now, I need to contend with the fact that I have to rotate the slider 180 degrees. Doing so results in this:
          slider.PNG
          As you can see, there are two problems with this:

          1. the text fields are backwards ("gpm" comes before "10")
          2. they're aligned at the top, not the bottom.

          Would the correct solution be to enclose this in an invisible rectangle, and make the Labels peers of the slider instead of children? Or is there a more elegant way to fix this?

          Thanks...

          EDIT: I added the following line to both Labels to get the text right side up:

          rotation: -circularSlider.rotation
          
          mzimmersM Offline
          mzimmersM Offline
          mzimmers
          wrote on last edited by
          #4

          I tried my idea above, and it seems to work (this code called from a main.qml):

          Item {
              anchors.centerIn: parent
          
              CircularSlider {
                  id: circularSlider
                  anchors.fill: parent
                  ...
              }
          
              CLabel {
                  id: nbr
                  anchors {
                      right: parent.horizontalCenter
                      rightMargin: 3
                      baseline: parent.verticalCenter
                  }
                  text: Number(circularSlider.value).toFixed()
                  font.pixelSize: 24
                  font.weight: Font.Bold
              }
              CLabel {
                  anchors {
                      left: parent.horizontalCenter
                      leftMargin: 3
                      baseline: nbr.baseline
                  }
                  text: "gpm"
              }
          }
          

          Produces this:
          slider.PNG

          Thanks for looking...

          1 Reply Last reply
          1

          • Login

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