Search code examples
tooltippyqt5qtreewidgetitem

PyQt5 - set toolTip for each QTreeWidgetItem


I have a GUI that uses a QTreeWidget to load a list of key - value pairs from a JSON file.

My question is if it's possible to set a tooltip for every item (just the keys) of the QTreeWidget?

P.S. I would like to keep the tree widget and do not move to QTreeView.


Solution

  • You could easily answer a questions like this by looking at the documentation for QTreeWidgetItem:

    void QTreeWidgetItem::setToolTip(int column, const QString &toolTip)

    Sets the tooltip for the given column to toolTip.

    Which in PyQt5 will simply be:

    item = QTreeWidgetItem(key)
    item.setToolTip(0, 'some text')