Results 1 to 3 of 3

Thread: Tooltips in QTableWidgetItem

  1. #1
    Join Date
    Jan 2006
    Location
    Leiden, the Netherlands
    Posts
    43
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Tooltips in QTableWidgetItem

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Tooltips in QTableWidgetItem

    Subclass QTableWidgetItem and reimplement data to return whatever text you want for Qt::ToolTipRole (3), like so:

    Qt Code:
    1. class MyTableWidgetItem : public QTableWidgetItem{
    2. public:
    3. void setToolTip(const QString &t){ m_tooltip = t; }
    4. QVariant data(int role){
    5. return role==3 ? m_tooltip : QTableWidgetItem::data(role);
    6. }
    7. private:
    8. QString m_tooltip;
    9. };
    To copy to clipboard, switch view to plain text mode 

    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");

  3. #3
    Join Date
    Jan 2006
    Location
    Leiden, the Netherlands
    Posts
    43
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Tooltips in QTableWidgetItem

    Thank you, that did the trick

Similar Threads

  1. Focus of cells in a QTableWidget
    By SailinShoes in forum Qt Programming
    Replies: 4
    Last Post: 9th June 2008, 08:19
  2. Replies: 1
    Last Post: 21st August 2007, 16:25
  3. QTableWidgetItem and formatting / input masks
    By Walter in forum Qt Programming
    Replies: 3
    Last Post: 27th July 2007, 13:39
  4. Interesting little Segfault w/r to signal/slot connection
    By Hydragyrum in forum Qt Programming
    Replies: 24
    Last Post: 12th September 2006, 19:22
  5. Tooltips & Qt4 tree views
    By yogeshm02 in forum Newbie
    Replies: 7
    Last Post: 17th January 2006, 15:12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.