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. [SOLVED] Why when the width is set for wrapMode, anchors.centerIn for text don't work?
QtWS25 Last Chance

[SOLVED] Why when the width is set for wrapMode, anchors.centerIn for text don't work?

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 1.3k 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.
  • H Offline
    H Offline
    honeyhong
    wrote on last edited by
    #1

    Hey I have these codes. And I want the text to wrap when the screen size change and yet still be in the center all the time.
    And I do not want to set a value to the width as it will be hard when changing to different device as they have different screen size.
    @
    BorderImage
    {
    id:headBar
    source:"../images/red.jpg"
    height:70
    width:parent.width
    anchors {top: header.bottom;}

        Text
        {   id:navigationText
            text:"Testing Super Long Text Here"
            //width:parent.width --> when I set this, text is wrap but not in the middle. without it, text couldn't be wrap.
            anchors.centerIn:parent
            color:"white"
            font.pixelSize: 30
            wrapMode: Text.WordWrap
      }
    }
    

    @
    I suspected something may be wrong with the width I set, but I've tried many ways.
    I want to wrap the text when size of the screen changes, and the text to be in the center.
    Can someone tell me why and how to fix it?

    1 Reply Last reply
    0
    • L Offline
      L Offline
      leafaku
      wrote on last edited by
      #2

      Hey hong,

      I spent half hour and found a solution maybe can solved your problem.
      Just add the two line to Text component:
      @horizontalAlignment : Text.AlignHCenter
      verticalAlignment : Text.AlignVCenter@

      BR,
      Leaf

      1 Reply Last reply
      0
      • H Offline
        H Offline
        honeyhong
        wrote on last edited by
        #3

        [quote author="leafaku" date="1343277513"]Hey hong,

        I spent half hour and found a solution maybe can solved your problem.
        Just add the two line to Text component:
        @horizontalAlignment : Text.AlignHCenter
        verticalAlignment : Text.AlignVCenter@

        BR,
        Leaf[/quote]

        Hey, I tried it and yeah, it worked! Took me half a day and I couldn't figure it out. Thank you so much for taking the time to help me. :)

        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