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. QML & Item geometry and internationalization
Forum Updated to NodeBB v4.3 + New Features

QML & Item geometry and internationalization

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 3 Posters 1.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.
  • M Offline
    M Offline
    malos
    wrote on last edited by
    #1

    Hi all,

    I am wondering how I could define item geometry different between different languages.
    Depending on the language, I may have to position items differently.
    One can imagine that a translated message would be longer and then would not fit in a predefined size rectangle.
    How to specify rectangle size depending on the language.

    As far as I understand, internationalization deals only with translating string and resource files deals with files to be embedded into application.

    How could I define qml properties like item geometry depending on language?

    Thanks for your reply.

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      Have a look at "FontMetrics":http://doc.qt.io/qt-5/qml-qtquick-fontmetrics.html.

      157

      1 Reply Last reply
      0
      • M Offline
        M Offline
        malos
        wrote on last edited by
        #3

        Ok, thks.
        But that applies to adjusting widget size according to font size.

        What if I want to have different item positions depending on language?

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          Well depending upon the width that you receive from FontMetrics you can adjust the positions of other Items.

          157

          1 Reply Last reply
          0
          • M Offline
            M Offline
            malos
            wrote on last edited by
            #5

            I was thinking of defining strings for position and size with a name idenitifying widget that could be translated and converted to integer values.

            But it looks tricky.

            1 Reply Last reply
            0
            • p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #6

              Using FontMetrics I would do it as follows:

              @
              Item {
              width: 400
              height: 400

              FontMetrics {
                  id: fontMetrics
                  font.family: "Comic Sans MS"
              }
              
              Rectangle {
                  id: rect
                  width: fontMetrics.height * 4
                  height: fontMetrics.height * 2
                  color: "red"
              }
              
              Rectangle {
                  y: rect.y+rect.height+10
                  width: fontMetrics.height * 4
                  height: fontMetrics.height * 2
                  color: "orange"
              }
              

              }
              @

              Now as your Font changes the last Rect gets adjusted as per previous which is binded to FontMetrics's width and height. Try changing the font and check the positions of those Rectangles.

              157

              1 Reply Last reply
              0
              • M Offline
                M Offline
                malos
                wrote on last edited by
                #7

                Ok, thks, I will try it.

                At the moment, I do not know if I will not have other cases that cannot be solved using font metrics.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #8

                  Wouldn't it be easier to use TextMetrics instead?

                  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