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] Center Text with letterSpacing
Forum Updated to NodeBB v4.3 + New Features

[solved] Center Text with letterSpacing

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

    I try to center text with non-default letterSpacing:

    @
    import QtQuick 2.2
    import QtQuick.Window 2.1

    Window {
    visible: true
    width: 360
    height: 360

    Text {
        text: qsTr("Hello World")
        anchors.centerIn: parent
        font.pointSize: 14
        font.letterSpacing: 20
    }
    

    }
    @

    but have no luck.

    Is there a proper way to do it?

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      It does centering with the above code ? What is the behaviour you observed ? It does put the spacing also at the end of the string as well.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

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

        [quote author="Dheerendra" date="1404651900"]It does centering with the above code ? What is the behaviour you observed ? It does put the spacing also at the end of the string as well.[/quote]

        I understand there is a spacing at the end.

        Nevertheless the question stays: is it possible to visually center text with big letterspacing?

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          At least question is not clear to me honestly now

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          0
          • H Offline
            H Offline
            habamax
            wrote on last edited by
            #5

            [quote author="Dheerendra" date="1404664711"]At least question is not clear to me honestly now[/quote]

            Well it is easy: I want text to be like this

            @

            T E X T
            -----------------------------------------------------------

            @

            Not this
            @

            T E X T
            -----------------------------------------------------------

            @

            1 Reply Last reply
            0
            • dheerendraD Offline
              dheerendraD Offline
              dheerendra
              Qt Champions 2022
              wrote on last edited by
              #6

              You want extra space in the beginning rather than the end. Is that correct ?

              Dheerendra
              @Community Service
              Certified Qt Specialist
              http://www.pthinks.com

              1 Reply Last reply
              0
              • H Offline
                H Offline
                habamax
                wrote on last edited by
                #7

                [quote author="Dheerendra" date="1404696896"]You want extra space in the beginning rather than the end. Is that correct ?[/quote]

                I don't want extra space at the end of the text.

                Looks like letterSpacing is a part of a letter and thus text with it could not be centered with anchors.

                I wonder if an additional space char at the beginnig of text would help. I'll check it when I back to my pc.

                1 Reply Last reply
                0
                • H Offline
                  H Offline
                  habamax
                  wrote on last edited by
                  #8

                  Adding one space at the beginnig of the text solves it. Visually it looks centered.

                  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