[SOLVED]anchors.CenterIn and anchors.horizontalCenter can't work



  • Qt4.8.1
    Mingw4.8.2
    win7 64bits

    MineText.qml
    @
    import QtQuick 1.1

    Text {
    id: mineText
    text: "Start"
    }
    @

    Main.qml
    @
    import QtQuick 1.0

    Rectangle {

    id: field
    width: 400; height: 400
    

    MineText{
    anchors.verticalCenter: field.verticalCenter
    //this line wouldn't work as expected, anchors.centerIn either
    anchors.horizontalCenter: field.horizontalCenter
    width: field.width - 20
    }
    }
    @

    The text "start" always appear on the "left" side rather than the horizontalCenter

    no warning or erros
    What kind of mistake do I make?Thanks


  • Moderators

    What happens if you

    you use something like :
    @
    MineText.qml

    Rectangle {
    Anchors.fill: parent.fill
    Text {
    anchors.horizontalcenter: parent.hrizontalcenter
    ...
    }
    }@



  • I try it but the result is the same
    @
    import QtQuick 1.0

    Rectangle {

    id: field
    width: 400; height: 400
    

    MineText{
    anchors.fill: parent.fill
    anchors.verticalCenter: parent.verticalCenter
    }
    }
    @

    Thanks for your reply



  • Your original code works for me. Perhaps you meant to also center the text inside the Text element?

    @
    import QtQuick 1.1

    Text {
    id: mineText
    text: "Start"
    horizontalAlignment: Text.Center
    }
    @

    Or you could simply not set an explicit size for the MineText



  • Thanks, you help me figure out the problem
    I didn't move the text to the center
    Thank you very much



  • Sorry, how could I mark this thread as "solved"?



  • Just add [SOLVED] in the title
    [quote author="stereomatching" date="1341476563"]Sorry, how could I mark this thread as "solved"?[/quote]


Log in to reply
 

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