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. Setting baseline
Forum Updated to NodeBB v4.3 + New Features

Setting baseline

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
8 Posts 2 Posters 971 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
    maxwell31
    wrote on last edited by
    #1

    Hi,

    I have an Item, which contains a TextField and a Text:

    Item {
        property bool displayTextField: true
        baseline: textField.baseline
        TextField {
            id: textField
            visible: displayTextField
        }
    
        Text {
            id: text
            visible: !displayTextField
        }
    
    }
    

    I would like to position this item using its baseline property. I thought in order to do this, I must set its baseline property to be either the baseline of textField or text, but if I try to do so I get the error

    qrc:/test.qml:14 Invalid property assignment: "baseline" is a read-only property
    
    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      There is baselineOffset property which is not read-only.

      But what is your goal? Why do you try to use baseline at all?

      (Z(:^

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

        I would like to align the text in the above item (either Textfield or Text depending on displayTextField) with the text of a label on the left of this item. Using top anchors is not working very well, as I use the Material style and then the text is below the label.

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Perhaps you can use verticalAlignment instead?

          (Z(:^

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

            Yes, but that means playing around a bit, I thought if I want to align the text baselines the obvious solution would be to anchor to baselines

            sierdzioS 1 Reply Last reply
            0
            • M maxwell31

              Yes, but that means playing around a bit, I thought if I want to align the text baselines the obvious solution would be to anchor to baselines

              sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              @maxwell31 said in Setting baseline:

              Yes, but that means playing around a bit, I thought if I want to align the text baselines the obvious solution would be to anchor to baselines

              But you are not anchoring them. You are trying to assign one value to another. Perhaps you've meant to write:

              Item {
                  property bool displayTextField: true
                  anchors.baseline: textField.baseline
                  // or
                  anchors.baseline: textField.anchors.baseline
              

              I've never tried any of this, but maybe it will work.

              (Z(:^

              1 Reply Last reply
              0
              • M Offline
                M Offline
                maxwell31
                wrote on last edited by
                #7

                It might be what I meant. I might have a problem of understanding here: Usually we can anchor items to another items baseline. If I design my own Item A, and would like some other Item B to be anchored to item As baseline, I must define somehow for Item A where its baseline is lying, right?

                sierdzioS 1 Reply Last reply
                0
                • M maxwell31

                  It might be what I meant. I might have a problem of understanding here: Usually we can anchor items to another items baseline. If I design my own Item A, and would like some other Item B to be anchored to item As baseline, I must define somehow for Item A where its baseline is lying, right?

                  sierdzioS Offline
                  sierdzioS Offline
                  sierdzio
                  Moderators
                  wrote on last edited by
                  #8

                  @maxwell31 said in Setting baseline:

                  It might be what I meant. I might have a problem of understanding here: Usually we can anchor items to another items baseline. If I design my own Item A, and would like some other Item B to be anchored to item As baseline, I must define somehow for Item A where its baseline is lying, right?

                  I guess so. I've never used the baseline property myself.

                  (Z(:^

                  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