Dynamic change text direction



  • Hello All,
    I write multi languages app, and get a little issue with text direction, when user check Arabic language (where direction right to left) text written in English not change direction, i can't imagine why... i try to set a LayoutDirection.Enable to true, it's not give a result. but if i close the app, and open it again, the direction of text will be correct. Why it's that? Any ideas?


  • Moderators

    Hi,

    According to "this":http://qt-project.org/doc/qt-5/qtquick-positioning-righttoleft.html#text-alignment it should be automatically be done.

    Following example works in Qt 5.3.1
    @
    Text {
    id: mytext
    anchors.fill: parent
    text: "Qt is Cool"
    }

    Button {
    anchors.bottom: parent.bottom
    text: "Arabic"
    onClicked: mytext.text = "مثال صغير"
    }

    Button {
    anchors.bottom: parent.bottom
    anchors.right: parent.right
    text: "English"
    onClicked: mytext.text = "Qt is Cool"
    }
    @



  • yes, but i have a some text at Arabic and at English (mixed), for example lable "Name" write at Arabic, and TextInput contains name in English. Arabic text align correct (to right side), but English text align to left side, it's not correct (to vision of Arabic)


  • Moderators

    Do you mean like this:
    @
    onClicked: mytext.text = "مثال صغير; Qt is Cool"
    @

    ?



  • i mean like this:
    @Text {
    text: "مثال صغير;"
    }
    TextInput {
    text: "Qt is Cool"
    }@


  • Moderators

    So you can do this:
    @
    TextInput {
    width: 200
    horizontalAlignment: Text.AlignRight
    text: "Qt is Cool"
    }
    @

    to align it to right.



  • yes, but when user change language to english for example, in element "Text" will be english text, not Arabic, and i should to set alignment of TextInput to LeftToRight


  • Moderators

    bq. yes, but when user change language to english for example, in element “Text” will be english text, not Arabic, and i should to set alignment of TextInput to LeftToRight

    Since your requirements need to override the default behavior for alignment of Text and TextInput you will have to change the alignments again. May be you can bind the horizontalAlignment property to the language chosen and accordingly set the required alignment.



  • i try to do that, when i set a new value of language direction is not chenged. but if i close and open agein app, then direction will be changed.


  • Moderators

    Can you post the relevant code where it shows the binding to horizontalAlignment ?


Log in to reply
 

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