PDA

View Full Version : Adding tooltips to canvas items



jnana
2nd March 2006, 05:55
Hi Every Body ,

I want to add tooltip to canvas items. I know how to add tooltips to widget objects. As canvas items are not derived from QWidget, therefore not able to add to it.

Needs all of your help.

Regard & Thanks

jpn
2nd March 2006, 07:08
Inherit Q3CanvasView and override:
bool QWidget::event ( QEvent * e ) [virtual protected]

You can show a dynamic tooltip like this:


bool MyCanvasView::event(QEvent *event)
{
if (event->type() == QEvent::ToolTip) {
QHelpEvent *helpEvent = static_cast<QHelpEvent*>(event);
// compare event position and canvas item positions
// and set tooltip text accordingly
QToolTip::showText(helpEvent->globalPos(), "");
}
return QWidget::event(event);
}

jnana
2nd March 2006, 10:53
Thanks JPN,

It is working fine.