[Qt-interest] A strange behavior of QGraphicsItem::contains()

Mihail Naydenov mlists at ymail.com
Sat Apr 24 11:12:49 CEST 2010


Hi, I am encountering a situation where QGraphicsItem::contains()
returns different result depending on whether its called from the Item itself or from one of its children: 

void Item::hoverEnterEvent ( QGraphicsSceneHoverEvent * e )
{

  QPointF localPoint = mapFromScene(_view->mapToScene(_view->mapFromGlobal(QCursor::pos())));

  qDebug()<<boundingRect().contains(localPoint);
  qDebug()<<rect().contains(localPoint);
  qDebug()<<contains(localPoint);
}

prints:
true 
true 
true


void ChildOfItem::hoverLeaveEvent ( QGraphicsSceneHoverEvent * e )
{
   // assume mouse moves over parent //

  QPointF localPoint = parentItem()->mapFromScene(_view->mapToScene(_view->mapFromGlobal(QCursor::pos())));

  qDebug()<<parentItem()->boundingRect().contains(localPoint);
  qDebug()<<parentWidget()->rect().contains(localPoint);
  qDebug()<<parentItem()->contains(localPoint);
}

prints:
true  
true 
false 

The result is the same if parentWidget() is used in all places;
(Of course isUnderMouse() also reports "false" form child)


Any ideas?
Thanks
MihailNaydenov


      



More information about the Qt-interest-old mailing list