Important: Please read the Qt Code of Conduct -

[Resolved] How to translate the enumeration of Qt

  • I want, according to the language of the machine, to translate the values ​​of the enumeration of Qt

    Which method allows me to do this? Is it possible?

  • What do you mean by "translate the values of the enumeration" and "enumeration of Qt"?

  • You mean you want to translate the values of an enumeration like this?
    enum ExampleEnum {
    SomeValue = 0,

    The only use case I see for that, is if you use Q_ENUM, make a property for the enum, and then create some kind of property-editor like UI that presents the possible values via introspection. It is possible, but I doubt that it is what you are are doing...

  • You could use some static method:

    QString TranslateEnum(ExampleEnum e)
    case SomeValue:
    return QObject::tr("Some Value");
    case AnotherValue:
    return QObject::tr("Another Value");
    case LastValue:
    return QObject::tr("Last Value");
    return QString();

  • Thanks for All. I have do it.
    How did I do?
    When I built the list of values for my enumeration, I put this value in tr (). And I tranlate that value in my file. <. ts>

    @QMetaEnum metaEnum = QObject::staticQtMetaObject.enumerator(index);
    QStringList enumNames;
    for (int i = 0; i < metaEnum.keyCount(); i++)
    enumNames << tr(metaEnum.key(i));

Log in to reply