QML & Item geometry and internationalization



  • 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.


  • Moderators

    Hi,

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



  • 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?


  • Moderators

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



  • 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.


  • Moderators

    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.



  • 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.



  • Wouldn't it be easier to use TextMetrics instead?


Log in to reply
 

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