PDA

View Full Version : tool tip for canvasitems



hayati
9th August 2006, 12:52
I'm trying to build a tooltipbox for qcanvas which is similar to QToolTip object.

i have a qcanvaspolygonalitem subclass objects displayed in qcanvasview. mouseTracking for qcanvasview is enabled. so i capture all mouseMoveEvents.When mouse pointer comes over one of the qcanvaspolygonalitem's bounding rect my tooltipbox object is shown and if pointer is out of all qcanvaspolygonalitems then this object should be hidden. i also added moving capability to qcanvaspolygonalitems using QWMatrix.

the problem is "when moving is started then hidden tooltipbox is shown without any show command(i hope so)"

i'll provide code snipplet below;

Note:
my ToolTip object is also polygonalitem.

thanks anyway,


void MyCanvasView::contentsMouseMoveEvent ( QMouseEvent * e )
{
QPoint p = e->pos();
QCanvasItemList l = m_pCanvas->allItems();
SomePolygonalItem* pSomePolygonalItem = 0;

// if mouse is pressed then moving is true
if ( moving ) {
for( QCanvasItemList::iterator it = l.begin(); it != l.end(); it++){
(*it)->moveBy(p.x() - moving_start.x(), p.y() - moving_start.y());
}

moving_start = p;
m_pCanvas->setAllChanged();
}
else {
for( QCanvasItemList::iterator it = l.begin(); it != l.end(); it++){
if ((*it)->rtti() == SomePolygonalItem::RTTI && (*it)->boundingRect().contains(p) ) {
pSomePolygonalItem = (SomePolygonalItem*) (*it);
break;
}
}

if pSomePolygonalItem {
// toString is a member function of SomePolygonalItem
// setText is member function of ToolTip object
m_pToolTip->setText( pSomePolygonalItem->toString() );
m_pToolTip->setX(p.x());
m_pToolTip->setY(p.y());
m_pToolTip->show();
}
else {
m_pToolTip->hide();
}
}


m_pCanvas->update();
}

hayati
9th August 2006, 14:41
guys, when i statically set all tooltips' text to the same string, then every thing goes ok. Strange???

hayati
10th August 2006, 08:39
ok, i found the solution now. I realized that; if tooltip objects's texts are the same then everything works ok. But when i change them dynamically then it becomes a disaster. Finallay i choose not to have only one tooltip for all canvas items, but to create a tooltip for each canvasitems. then everthing becomes ok now.

:)