-1

我想在 QTreeView 的特定单元格中显示一个 QComboBox。我知道我必须为此使用自己的模型。整个事情已经在单元格中显示的 QIcons 上正常工作,但我没有用组合框做同样的事情。这就是我的模型的样子(一些不完整的伪代码):

QVariant MyListModel::data(const QModelIndex &index, int role) const
{
   ...

   switch(role)
   {
      ...
      case Qt::DecorationRole:
         switch(index.column())
         {
            case eBLA:
               // return QIcon(); --> compiles properly
               return m_placePosCombos[index.row()]; --> compilation fails
               return QComboBox(); --> compilation fails
               break;
            default:

当我尝试返回一个 QComboBox 时,我得到一个编译错误

cannot convert from 'const QComboBox' to 'QVariant'

MyListModel 继承自 QAbstractListModel。

知道我必须做什么才能使用 QComboBox 而不是愚蠢的图标吗?

谢谢!

4

1 回答 1

2

不,模型仅用于视图中的数据处理,而不用于更改视图。您需要学习和使用:QItemDelegate(抱歉没有在这里显示所有代码,它需要时间和地点......您可能需要阅读tuto和相关文档的时间......希望有所帮助)

QItemDelegate 教程

QItemDelegate API 类 Qt5

于 2016-08-17T06:55:04.633 回答