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();
}
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();
}