【发布时间】:2016-08-17 06:48:39
【问题描述】:
我想在 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 而不是愚蠢的图标吗?
谢谢!
【问题讨论】:
-
您不能通过复制(或移动)返回
QObject,也不能将一个包裹在QVariant中(尽管您可以存储指向一个的指针)。
标签: c++ qt qt5 qcombobox qabstractlistmodel