Why does handling the tool tip role cause my entry not to show in my combo box?

16 Views Asked by At

I'm handling tool tips for some items in my model, but the ones with tool tips are hidden/absent in my combo box drop-down. Here is the data function of the model I'm using in my combo box:

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 {};
   }
}
1

There are 1 best solutions below

0
jtooker On

case Qt::ToolTip: should be case Qt::ToolTipRole:.

Qt::ToolTip matches Qt::SizeHintRole - and when QVariant("any test") is interpreted as a QSize it is -1, -1 causing the combo box to not show it.