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]anchors.CenterIn and anchors.horizontalCenter can't work

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

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 4 Posters 16.6k 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.
  • S Offline
    S Offline
    stereomatching
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

      What happens if you

      you use something like :
      @
      MineText.qml

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

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      0
      • S Offline
        S Offline
        stereomatching
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MartinJ
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • S Offline
            S Offline
            stereomatching
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • S Offline
              S Offline
              stereomatching
              wrote on last edited by
              #6

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

              1 Reply Last reply
              0
              • R Offline
                R Offline
                raaghuu
                wrote on last edited by
                #7

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

                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