×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Regular Contributor
    Join Date
    Apr 2008
    Posts
    445

    Qml SelectionDialog and qsTr

    Hi,

    I work with a Qt Components selection dialog:
    Code:
    SelectionDialog {
    	titleText: qsTr("Title text")
    	selectedIndex: 2
    	model: ListModel {
    		ListElement { name: "A" }
    		ListElement { name: "B" }
    		ListElement { name: "C" }
    	}
    	onAccepted: fncDoSomething(selectedIndex);
    }
    Now for internationalization I need to translate the ListElement texts, (A, B, C). I already found a workaround for ListBox which uses a Javascript function [1] but this does not work with the selection dialog.

    [Edit]: I know that I can manually feed a list model from C++ and use tr() there but I would prefer to directly do the translation in Qml.

    How can I translate these ListElement entries?

    G.

    [1] http://qt-project.org/wiki/Qt_Quick_...264ad0443ae759

  2. #2
    Nokia Developer Expert
    Join Date
    Oct 2007
    Posts
    441

    Re: Qml SelectionDialog and qsTr

    Hi pixta

    Can you have localized versions of you component and use it with loader ? For example : ListModel in your case is defined in a separate file where strings are localized and localization variant is selected on component construction by some criteria (see pseudo-code below). I believe that should work

    Code:
    // client code
    
    Loader { id: loader }
    
    Component.onComplete(){
             var model = "ModelLangDefault.qml"
             if(language id is equal to "ID")
                   model = "ModelLangID.qml";
             else if(...)...
             load.source = model;
    }
    
    SelectionDialog {
    	titleText: qsTr("Title text")
    	selectedIndex: 2
    	model: loader.target
    	onAccepted: fncDoSomething(selectedIndex);
    }

  3. #3
    Nokia Developer Expert
    Join Date
    Jun 2012
    Posts
    55

    Re: Qml SelectionDialog and qsTr

    Another possible solution is create "empty" ListElements and then on ListModel completed use qsTr on the elements.

    Code:
    model: ListModel {
        id: list
        ListElement { name: "" }
        ListElement { name: "" }
        ListElement { name: "" }
    
        Component.onCompleted: {
            list.get(0).name = qsTr("A")
            list.get(1).name = qsTr("B")
            list.get(2).name = qsTr("C")
        }
    }
    Br,
    Villep

  4. #4
    Regular Contributor
    Join Date
    Apr 2008
    Posts
    445

    Re: Qml SelectionDialog and qsTr

    Thanks! Works like a charme.

Similar Threads

  1. Qt Quick SelectionDialog with dynamic content from C++
    By oskari.petas in forum [Archived] Qt Quick
    Replies: 14
    Last Post: 2012-02-06, 09:32
  2. How to select item in SelectionDialog manually?
    By evgeny_123 in forum [Archived] Qt Quick
    Replies: 14
    Last Post: 2012-01-19, 05:56
  3. SelectionDialog and C++ model on Harmattan
    By vladest in forum [Archived] Qt Quick
    Replies: 2
    Last Post: 2011-11-27, 10:38
  4. [S60,9.1]IAP-SelectionDialog pops up twice
    By tobias_stoeger in forum Symbian Signed Support, Application Packaging and Distribution and Security
    Replies: 14
    Last Post: 2008-03-14, 11:37
  5. [S60,9.1]IAP-SelectionDialog pops up twice
    By tobias_stoeger in forum Symbian Networking & Messaging (Closed)
    Replies: 8
    Last Post: 2006-05-24, 14:19

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×