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. anchoring qml text item using baseline

anchoring qml text item using baseline

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 3.5k Views
  • 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
    AYYAPPA
    wrote on last edited by AYYAPPA
    #1

    hello ,

    I am not able to understand how to anchor qml text item using anchors.baseline property.
    Lets say i have rectangular box 100x200 size and i want to place text item on baseline (y= 40). how can i achieve that?
    currently i am assigning anchors.baseline to (y = 40) which is a line parallel to x axis at a height of 40 on which i want my text item to sit.
    and what is the use of anchors.baselineOffset ?? i am confused !!

    ex:
    Text{
    id: name
    x: 316
    anchors.baseline: (y = 40)
    text = "Hello!"
    font.pixelSize: 16
    }

    1 Reply Last reply
    0
    • 6thC6 Offline
      6thC6 Offline
      6thC
      wrote on last edited by
      #2

      This should help understanding the various anchors.
      https://doc-snapshots.qt.io/qt5-dev/qtquick-positioning-anchors.html

      Not sure about the baseline thing your trying. But docu verbatim; says:

      The baseline (not pictured above) corresponds to the imaginary line on which text would sit. For items with no text it is the same as top.
      

      What about in your text item:

      anchors { bottom: parent.bottom; bottomMargin : 40; }
      

      You are:

      • setting x to out of range for your example of 100*200
      • manually setting position with x and anchors is probably going to end up badly.

      If you want precise control you can use x sure.
      You can bind x (to an expression, another object, many things)
      Anchors
      Layouts.

      I'd hazard a guess you have a little bit of reading for the basics - there's a QML book @ https://qmlbook.github.io/index.html that helped when I was starting and sometimes look at.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        AYYAPPA
        wrote on last edited by AYYAPPA
        #3

        hi 6thc thanks for your answer ,i have a very basic question here..
        i just want to know how to assign the "anchors.baseline" and "anchors.baselineOffse" properties in text without actually using some other item's anchors.

        look at example i provided below. now i am not using x, y positions ,as you can see only anchors are used.

        example:
        option1: this works fine to keep text1 basline at y=40 relative to parentRect.

        Rectangle{
        id: parentRect

        Rectangle{
        id: rect1

        x: 0
        y: 40
        height: 1
        width = 200
        color = "white"
        }

        Text{
        id: text1
        anchors.left : parent.left
        anchors.baseline : rect.top
        }
        }

        option 2: what if there is no other sibling rectangle, what should be the value to pass to anchors.baseline property of text1 tokeep text1 basline at y=40 relative to parentRect ? and again dont use parent.top or bottom and give baslineOffset that works too. i just wanted to learn about QQuickAnchorLine class objects
        Rectangle{
        id: parentRect
        Text{
        id: text1
        anhcors.left: parent.left
        anchors.baseline = ?
        }
        }

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

          i guess i was not clear about my question , currently works well using baseline and baslineoffset .
          how can i move this to solved?

          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