为什么处理工具提示角色会导致我的条目不显示在组合框中?

问题描述 投票:0回答:1

我正在处理模型中某些项目的工具提示,但带有工具提示的项目在我的组合框下拉列表中隐藏/不存在。这是我在组合框中使用的模型的

data
函数:

QVariant MyModel::data(const QModelIndex& index, const int role) const
{
   const DataStruct& data = m_data[index.row()];
   switch (role)
   {
      case Qt::DisplayRole:
         return data.name;

      case Qt::EditRole:
      case Qt::UserRole:
         return QVariant::fromValue(data.value);

      case Qt::ToolTip:
         if (data.condition)
         {
            return tr("Tool tip text");
         }
         return {};

      default:
         return {};
   }
}
qt model qcombobox
1个回答
0
投票

case Qt::ToolTip:
应该是
case Qt::ToolTipRole:

Qt::ToolTip
匹配
Qt::SizeHintRole
- 当 QVariant("any test") 被解释为
QSize
时,
-1, -1
会导致组合框不显示它。

© www.soinside.com 2019 - 2024. All rights reserved.