Reputation: 33607
I want to display a tooltip for QTreeWidgetItem
that's hovered. However, getting a tooltip is not a very fast process in my case, so I don't want to call setTooltip()
for every single item. I want to do it on demand, on some event or signal. What's the easiest way to do it?
Upvotes: 3
Views: 4235
Reputation: 33607
The best solution I've found is to subclass QTreeWidgetItem
, override virtual QVariant data(int column, int role) const;
and return a tooltip for this item when data
is called for Qt::ToolTipRole
.
Upvotes: 5
Reputation: 2017
I think that it should be easier to achieve what you want if you migrate to a QTreeView/Model pattern.
QAbstractItemModel has a role for tooltips: Qt::ToolTipRole
You could subclass a Model to reimplement the
QVariant QAbstractItemModel::data ( const QModelIndex & index, int role = Qt::DisplayRole ) const [pure virtual
method.
So, when receives a Qt::TooltipRole, it calculates/recovers from an internal cache.
Upvotes: 0