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. Text Alignment
Qt 6.11 is out! See what's new in the release blog

Text Alignment

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 13.3k 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.
  • M Offline
    M Offline
    Madesh R
    wrote on last edited by J.Hilk
    #1

    Hi All,

    I want to align text to the center of rectangle if the length of the string is less.
    Or else i need to make the text to fit into the parent.

    How do I achieve it.
    Below is the code that tried, But unable to align it to center when the text is less in length

    Rectangle{
         width:200
         height:60
         color: "lightgray"
         Text{
             anchors.fill: parent
             font.pixelSize: 24
             text: "Some Some" /*"SOme Text SOme Text SOme Text SOme text sdjhsakcjcsdkvkjds"*/
             fontSizeMode: Text.Fit
             minimumPixelSize: 10
             wrapMode: Text.WordWrap
    
            horizontalAlignment:  parent.horizontalCenter
            verticalAlignment: parent.verticalCenter
         }
     }
    

    Edit[j.hilk]:added missing code tags for better reading

    J.HilkJ 1 Reply Last reply
    0
    • M Madesh R

      Hi All,

      I want to align text to the center of rectangle if the length of the string is less.
      Or else i need to make the text to fit into the parent.

      How do I achieve it.
      Below is the code that tried, But unable to align it to center when the text is less in length

      Rectangle{
           width:200
           height:60
           color: "lightgray"
           Text{
               anchors.fill: parent
               font.pixelSize: 24
               text: "Some Some" /*"SOme Text SOme Text SOme Text SOme text sdjhsakcjcsdkvkjds"*/
               fontSizeMode: Text.Fit
               minimumPixelSize: 10
               wrapMode: Text.WordWrap
      
              horizontalAlignment:  parent.horizontalCenter
              verticalAlignment: parent.verticalCenter
           }
       }
      

      Edit[j.hilk]:added missing code tags for better reading

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by J.Hilk
      #2

      hi @Madesh-R

      that are not the correct binding for text alignment

      Rectangle{
         width:200
         height:60
         color: "lightgray"
         Text{
             anchors.fill: parent
             font.pixelSize: 24
             text: "Some Some" /*"SOme Text SOme Text SOme Text SOme text sdjhsakcjcsdkvkjds"*/
             fontSizeMode: Text.Fit 
             minimumPixelSize: 10
             wrapMode: Text.WordWrap
      
             horizontalAlignment: Text.AlignHCenter
             verticalAlignment: Text.AlignVCenter
        }
      }
      

      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      M 1 Reply Last reply
      8
      • J.HilkJ J.Hilk

        hi @Madesh-R

        that are not the correct binding for text alignment

        Rectangle{
           width:200
           height:60
           color: "lightgray"
           Text{
               anchors.fill: parent
               font.pixelSize: 24
               text: "Some Some" /*"SOme Text SOme Text SOme Text SOme text sdjhsakcjcsdkvkjds"*/
               fontSizeMode: Text.Fit 
               minimumPixelSize: 10
               wrapMode: Text.WordWrap
        
               horizontalAlignment: Text.AlignHCenter
               verticalAlignment: Text.AlignVCenter
          }
        }
        
        M Offline
        M Offline
        Madesh R
        wrote on last edited by
        #3

        @J.Hilk

        Thank you Hilk. It's working... :)

        J.HilkJ 1 Reply Last reply
        0
        • M Madesh R

          @J.Hilk

          Thank you Hilk. It's working... :)

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @Madesh-R
          great, and you're welcome ;-)

          Don't forget to set the top to solved, is your issue has indeed been solved ;-)


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          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