[SOLVED]--QProperty's International



  • Hello,
    I'm trying to use Meta-Object System to build a property editor like Qt Designer.

    I declare a Q_Property thing like this
    @Q_PROPERTY(QString myText READ getTextWRITE setText DESIGNABLE true)@
    in a class.

    I think I make DESIGNABLE true so that the property myText can be visible in the property editor.

    But the question comes when I try to show this property ,myText ,in another language.I have no idea about making the name of the very property, myText , to be shown in Japanese etc.

    i.e. In the declaration
    @ Q_PROPERTY(type name READ getFunction WRITE setFunction DESIGNABLE true@
    can name be translated into another language in a GUI?
    Where should I put tr()?

    Thanks!



  • The only option I see is to add a method to the class and do it there. Properties are typically a developement thing so they are in english only. The only one (in a generic approach) who could translate it is the class, so add something like:

    @
    class CFoo
    {
    Q_PROPERTY(QString myText READ getText WRITE setText DESIGNABLE true)
    Q_PROPERTY(QString name READ getText WRITE setText DESIGNABLE true)
    public:
    // ...
    public slots:
    QString translatePropertyName(QString szName, QString targetLanguage);
    }
    @



  • The Q_PROPERTY macros serve only as a marker for moc and pre-processes out of the code for the compiler: so you cannot put executable code in there. The names must also be constructed of single byte characters suitable for use in a C-style string because that is what moc and QMetaObject does with them.



  • Thank you. It seems to work.
    [quote author="Gerolf" date="1340263596"]The only option I see is to add a method to the class and do it there. Properties are typically a developement thing so they are in english only. The only one (in a generic approach) who could translate it is the class, so add something like:

    @
    class CFoo
    {
    Q_PROPERTY(QString myText READ getText WRITE setText DESIGNABLE true)
    Q_PROPERTY(QString name READ getText WRITE setText DESIGNABLE true)
    public:
    // ...
    public slots:
    QString translatePropertyName(QString szName, QString targetLanguage);
    }
    @[/quote]



  • I extended YAPE (to be found on qtapps.org) once to support these and other additional options. I ended up adding an optional special property to the objects I wanted to show. For every property that I had additional attributes for, I'd create a (dynamic) property <PropertyName>attributes, that contained a QVariantHash with additional attributes. Such properties included the editor name (to get a non-standard editory like a file name selector for a QString property), placeholder text in the editor, limits for valid value ranges, tooltips, etc.

    Code is available under LGPL if you are interested.



  • [quote author="Andre" date="1346920355"]

    Code is available under LGPL if you are interested.[/quote]

    Can you give a code of extended YAPE?



  • Look for srtools on assembla.com (currently down, so I can't give you a direct link right now).

    Then in the repository, find common/propertyeditor/



  • Seems I found it. Thanks!
    https://www.assembla.com/code/srtools/git/nodes/addressTool/common/propertyeditor
    But it show me only properties-flags.
    Will investigate more.
    Also no attributes for valid value ranges.


Log in to reply
 

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