Hi,
Is it possible to display tooltips when hovering over items in the tableview?
Regards,
Steve
Hi,
Is it possible to display tooltips when hovering over items in the tableview?
Regards,
Steve
==========================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.
or QAbstractItemModel::setData with Qt::ToolTipRole.
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:
{ QVariant data; if( role == Qt::ToolTipRole) // do whateverTo copy to clipboard, switch view to plain text mode
If so, what do I do?
Regards,
Steve
Yes, like that.
From data you return whatever text you want the tooltip to display.
Regards
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
The default delegate will ask the model for tooltip. If you return one, it'll display it.
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:
if( role == Qt::ToolTipRole ) { data = "Signal"; }To copy to clipboard, switch view to plain text mode
Regards,
Steve
return "Signal" and not data = "Signal". What is "data" anyway?
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
It should if you didn't change the delegate. Could you show us the complete data() method?
Sure, here it is :
Qt Code:
{ QVariant data; if (!index.isValid()) if(index.column() > 4 ) { } if( role == Qt::ToolTipRole ) { data = "Signal"; } if( role == Qt::DisplayRole ) { CDADcb::CSignal* pSignals; pSignals = (CDADcb::CSignal*)theApp->m_dcb.GetSignalList()->at(index.row()); switch( index.column() ) { case SIGNALNAME : { data = pSignals->name; break; } case DATA : { data = pSignals->m_strRawData; break; } case UNIT : { data = pSignals->unit; } break; case COUNT : { data = pSignals->m_nCount; } break; } } return data; }To copy to clipboard, switch view to plain text mode
Regards,
Steve
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
It could be wise to sometimes returning something else than the same text
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
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.
Thanks,
That would be fine, this standard QToolTip?
Regards,
Steve
Yes, stardard tooltip formatted with html as a table.
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
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.
steg90 (17th May 2007)
Bookmarks