Qt中的翻译问题
Problems with translation in Qt
我在使用 Qt 翻译时遇到问题:
在表格视图中,我正在使用委托来获取组合框作为编辑功能:
this->gndDelegate = new GenderDelegate(this);
ui->tableView->setItemDelegateForColumn(AthleteModel::GENDER_COLUMN, this->gndDelegate);
组合框有值,我想用tr()
命令翻译这些值。所有其他翻译工作正常,但这两个添加的项目未翻译:
QWidget *GenderDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QComboBox *cmbBox = new QComboBox(parent);
cmbBox->addItem(tr("male"), "male");
cmbBox->addItem(tr("female"), "female");
return cmbBox;
}
对于这两个值,qm 文件中存在表示
形式感谢您的帮助...
必须在委托实现中添加指令Q_OBJECT。例如:
class KeyConfigurationDelegate : public QItemDelegate
{
Q_OBJECT //Add This directive !!!
public:
explicit KeyConfigurationDelegate(QObject *parent = 0);
~KeyConfigurationDelegate();
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void setEditorData(QWidget *editor, const QModelIndex &index) const;
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
private:
QStringList list;
QStringListModel model;
};
相关文章:
- 警告处理为错误这里有什么问题
- 最小硬币更换问题(自上而下方法)
- 为"adjacent"变量赋值时出现问题
- 我的神经网络不起作用 [XOR 问题]
- 在Ubuntu 16.04上安装Cilk时出现问题
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 编译包含字符串的代码时遇到问题
- Project Euler问题4的错误解决方案
- 问题:什么是QAbstractItemView::NoEditTriggers的反面
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 在进程中对同一管道进行读取和写入时C++管道出现问题
- 在 opengl 中翻译相机时遇到问题
- SDK指针的问题 - c++到德尔福的翻译
- 处理Qiloader时的Qt翻译问题
- Qt插件翻译出现问题
- Qt中的翻译问题
- 常量字符* 与C++的双重翻译问题
- 翻译多维数据集时出现问题
- 将Python算法翻译成C++时遇到问题
- 翻译/音译问题