[SOLVED] How to disable tooltips from QTableWidgetItem
-
Hi!
After trying several strategies I couldn't disable tooltips from the cells of a QTableWidget.
Any suggestion? Thanks!
-
Tooltips don't appear out of nowhere. If they're there then you probably set them somewhere. To remove a tooltip from an item just don't set it at all or set it to an empty string, eg.
@tableWidget->item(row, column)->setToolTip(QString());@ -
But what if there is no any tooltip related instruction in the whole QTableWidget class based I created?
Here is my code in case you want to check it:
http://www.maefloresta.com/portal/files/tupframestable.cppIt seems there is some kind of tooltip default action related to the QTableWidget/QTableWidgetItem classes.
-
Nope, there isn't:
@
int main(int argc, char *argv[])
{
QApplication a(argc, argv);QTableWidget tw(1, 1); tw.setItem(0,0, new QTableWidgetItem("very long text that can't possibly fit")); tw.show(); return a.exec();
}
@
No tooltip.Your code is that of tablewidget and tablewidgetitem but it all depends on how it is used. Where are the items created and inserted into the table? Maybe the tooltips are set there?
-
Well, after several tests finally I found the reason I was getting tooltips without calling the setToolTip() method. I was using "exotic" values (0x01, 0x02, 0x03) for the parameter role in the method "setData()":http://qt-project.org/doc/qt-5/qtablewidgetitem.html#setData
I could confirm it adding some lines to your sample:
@
int main(int argc, char *argv[])
{
QApplication a(argc, argv);QTableWidget tw(1, 1); QTableWidgetItem *item = new QTableWidgetItem; item->setData(0x01, "very long text that can't possibly fit"); item->setData(0x02, true); item->setData(0x03, "Guess what?"); // <- this will be the tooltip text tw.setItem(0, 0, item); tw.show(); return a.exec();
}
@ -
Hi,
That's why there's Qt::UserRole which is the starting point for custom roles in your application
-
Thank you! Nice hint :)
-
Yeah, I'd say you got what you deserved ;) That's the kind of errors enums were invented for. 0x3 happens to be the value of Qt::TooltipRole but nobody said it's gonna stay that way forever. It can become Qt::DestroyTheWorld in Qt6 and we'll know who to thank for the trouble ;)