Results 1 to 20 of 23

Thread: Tooltip on item in tableview

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Tooltip on item in tableview

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

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

    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

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    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?

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

    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

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

    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

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

    Default Re: Tooltip on item in tableview

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

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

    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

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    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

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

    Default Re: Tooltip on item in tableview

    Thanks,

    That would be fine, this standard QToolTip?

    Regards,
    Steve

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

    Default Re: Tooltip on item in tableview

    Yes, stardard tooltip formatted with html as a table.

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

    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

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    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.

  13. 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
  •  
Qt is a trademark of The Qt Company.