Page 1 of 2 12 LastLast
Results 1 to 20 of 23

Thread: Tooltip on item in tableview

  1. #1
    Join Date
    May 2007
    Posts
    301
    Thanks
    46
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Tooltip on item in tableview

    Hi,

    Is it possible to display tooltips when hovering over items in the tableview?

    Regards,
    Steve

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Tooltip on item in tableview

    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    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: Tooltip on item in tableview

    or QAbstractItemModel::setData with Qt::ToolTipRole.

  4. #4
    Join Date
    May 2007
    Posts
    301
    Thanks
    46
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Tooltip on item in tableview

    Hi,

    setData, would I use this in my custom model? I'm presuming that I can then do a comparison in my data function in my model to see if the role is Qt::ToolTipRole ?


    Snippet below :
    Qt Code:
    1. QVariant DACanTreeModel::data(const QModelIndex &index, int role) const
    2. {
    3. QVariant data;
    4. if( role == Qt::ToolTipRole) // do whatever
    To copy to clipboard, switch view to plain text mode 

    If so, what do I do?

    Regards,
    Steve

  5. #5
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Tooltip on item in tableview

    Yes, like that.
    From data you return whatever text you want the tooltip to display.

    Regards

  6. #6
    Join Date
    May 2007
    Posts
    301
    Thanks
    46
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Tooltip on item in tableview

    Thanks,

    Ok, but I don't call setData anywhere in my model, I just update the data structures it uses. Will the role be Qt::ToolTipRole at some point or do I need to use setData for this to happen??

    Regards,
    Steve

  7. #7
    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: Tooltip on item in tableview

    The default delegate will ask the model for tooltip. If you return one, it'll display it.

  8. #8
    Join Date
    May 2007
    Posts
    301
    Thanks
    46
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Tooltip on item in tableview

    Hi,

    I thought this also, but no tooltip is displayed?

    In my data method I just did this so I thought the tooltip would be shown as 'Signal', but nothing appears.


    Qt Code:
    1. if( role == Qt::ToolTipRole )
    2. {
    3. data = "Signal";
    4. }
    To copy to clipboard, switch view to plain text mode 

    Regards,
    Steve

  9. #9
    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: Tooltip on item in tableview

    return "Signal" and not data = "Signal". What is "data" anyway?

  10. #10
    Join Date
    May 2007
    Posts
    301
    Thanks
    46
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Tooltip on item in tableview

    Hi,

    Sorry wysota, data is QVariant and at the bottom of the function I return data. I set a breakpoint in my data method to break when the role is Qt::ToolTipRole, but it never breaks.

    Regards,
    Steve

  11. #11
    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: Tooltip on item in tableview

    It should if you didn't change the delegate. Could you show us the complete data() method?

  12. #12
    Join Date
    May 2007
    Posts
    301
    Thanks
    46
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Tooltip on item in tableview

    Sure, here it is :

    Qt Code:
    1. QVariant DACanTreeModel::data(const QModelIndex &index, int role) const
    2. {
    3. QVariant data;
    4.  
    5. if (!index.isValid())
    6. return QVariant();
    7. if(index.column() > 4 )
    8. {
    9. return QVariant();
    10. }
    11. if( role == Qt::ToolTipRole )
    12. {
    13. data = "Signal";
    14. }
    15. if( role == Qt::DisplayRole )
    16. {
    17. CDADcb::CSignal* pSignals;
    18. pSignals = (CDADcb::CSignal*)theApp->m_dcb.GetSignalList()->at(index.row());
    19. switch( index.column() )
    20. {
    21. case SIGNALNAME : {
    22. data = pSignals->name;
    23. break;
    24. }
    25. case DATA : {
    26. data = pSignals->m_strRawData;
    27. break;
    28. }
    29. case UNIT : {
    30. data = pSignals->unit;
    31. }
    32. break;
    33. case COUNT : {
    34. data = pSignals->m_nCount;
    35. }
    36. break;
    37. }
    38. }
    39. return data;
    40. }
    To copy to clipboard, switch view to plain text mode 

    Regards,
    Steve

  13. #13
    Join Date
    May 2007
    Posts
    301
    Thanks
    46
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Tooltip on item in tableview

    Sorry about this, the tool tip is now displaying...unfortunately it won't go away unless I click on the table...even if I move the mouse it won't disappear?!

    Regards,
    Steve

  14. #14
    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: Tooltip on item in tableview

    It could be wise to sometimes returning something else than the same text

  15. #15
    Join Date
    May 2007
    Posts
    301
    Thanks
    46
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Tooltip on item in tableview



    I guess it is! It does now work. I must admit, I'd prefer a custom tooltip. Is it possible to set up a different delegate so when user hovers over an item, a custom tooltip appears instead of the standard one?

    Kind regards,
    Steve

  16. #16
    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: Tooltip on item in tableview

    What kind of custom tooltip? You can use rich text in your tooltips if you want. Should be sufficient in most cases. See attachment for one of my tooltips.
    Attached Images Attached Images

  17. #17
    Join Date
    May 2007
    Posts
    301
    Thanks
    46
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Tooltip on item in tableview

    Thanks,

    That would be fine, this standard QToolTip?

    Regards,
    Steve

  18. #18
    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: Tooltip on item in tableview

    Yes, stardard tooltip formatted with html as a table.

  19. #19
    Join Date
    May 2007
    Posts
    301
    Thanks
    46
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Tooltip on item in tableview

    Ok, so I could just display the tooltip with the QToolTip::showText method? Do I just format the text as html in the QString?

    Regards,
    Steve

  20. #20
    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: Tooltip on item in tableview

    You can just set the appropriate tooltip in your model and Qt will display it. No need to mangle the default tooltip system.Yes, just use the subset of HTML supported by Qt.

  21. The following user says thank you to wysota for this useful post:

    steg90 (17th May 2007)

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.