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. Anchors problem with several texts
Forum Updated to NodeBB v4.3 + New Features

Anchors problem with several texts

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 3 Posters 3.0k 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.
  • M Offline
    M Offline
    micha4fun
    wrote on last edited by
    #1

    Hello,

    I try to align text fragments of different sizes (point). I thought if I anchor 2 elements at the top of each other, they would start at the same y-value. But it seems in texts there are existing special rules. The following example shows what I intend to do.

    @
    Rectangle
    {
    width: 360
    height: 360

    Text
    {
         id: t1
         x: 50
         y: 40
    
         text: "A"
    
         font.family: "Verdana";
         font.weight: Font.Normal
         font.pointSize: 40
    }
    
    Text
    {
         id: t2
    
         text: "B"
    
         font.family: "Verdana";
         font.weight: Font.Normal
         font.pointSize: 20
    
         anchors.bottom: t1.bottom
         anchors.left: t1.right
    }
    
    Text
    {
         id: t3
    
         text: "C"
    
         font.family: "Verdana";
         font.weight: Font.Normal
         font.pointSize: 10
    
         anchors.top: t2.top
         anchors.left: t2.right
    }
    

    }
    @

    Edit: fixed code indentation for improved readability; Andre

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mbrasser
      wrote on last edited by
      #2

      Do you have an image of what you are trying to achieve? If the goal is to have the different sized texts all "sitting on the same line", you should be able to use anchors.baseline.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        micha4fun
        wrote on last edited by
        #3

        Hmm ... strange. I thought I made this test as well. :/
        It works like expected for the first 2 letters. So thank you again!

        But while t1 and t2 are sitting now on the same baseline, I still don't see a way to align t3 to the "topline" of letter t2 (both letters start on the same y-value). I tried something like this for t3:

        @
        anchors.baseline: t2.baseline
        anchors.baselineOffset: -( t2.paintedHeight - paintedHeight )
        @

        But don't work.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          Could you post an image, complete with the relevant guide lines, of what you are trying to achieve please?

          1 Reply Last reply
          0
          • M Offline
            M Offline
            micha4fun
            wrote on last edited by
            #5

            Of course, here is the image for baseline usage t1/t2 and code snippet from last post for t2/t3 :)

            !http://www.treggs.de/img/Image1.png(Baseline image)!

            Edit: fixed image tag. Image tag gets screwed if you don't enter an alternative text; Andre

            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