PDA

View Full Version : Tooltips in QTableWidgetItem



Arthur
24th January 2006, 18:09
Hello,

I would like my QTableWidgetItems (and headers) to have tooltips. Using the setToolTip method does not result in the fact that the tooltip is displayed when 'hovering'.

Apparently I missed something, but for instance buttons, etc it works. Could someone help me on this one?

Thanks,

Arthur

wysota
24th January 2006, 21:10
Subclass QTableWidgetItem and reimplement data to return whatever text you want for Qt::ToolTipRole (3), like so:


class MyTableWidgetItem : public QTableWidgetItem{
public:
void setToolTip(const QString &t){ m_tooltip = t; }
QVariant data(int role){
return role==3 ? m_tooltip : QTableWidgetItem::data(role);
}
private:
QString m_tooltip;
};

Edit:
I just noticed there is a setData() member available for QTableWidgetItem, so all you have to do is to call setData(3, "My Tooltip");

Arthur
26th January 2006, 16:47
Thank you, that did the trick