我在使用Qt翻译时遇到问题:
在tableView中,我使用Delegate将Combo Box作为编辑功能:
this->gndDelegate = new GenderDelegate(this);
ui->tableView->setItemDelegateForColumn(AthleteModel::GENDER_COLUMN, this->gndDelegate);
ComboBox有值,我想用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文件中的表示感谢您的帮助......
答案 0 :(得分:2)
您必须在委托实现中添加指令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;
};