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



  • 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?



  • 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 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. :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.