Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 6

Qt-interest Archive, March 2007
I must be missing something WRT mouse hover events


Message 1 in thread

I need to modify a group of graphics items when the mouse hovers over that
particular group.  The items are grouped within myItemGroup, a subclass of
QGraphicsItemGroup.  I have written code for the hover enter and leave
event handlers, but these never seem to get invoked.

I am obviously overlooking something, but I'm stumped and would appreciate
some help.  Here is a code snippet to illustrate:

class myItemGroup : public QObject, public QGraphicsItemGroup
{
  Q_OBJECT
...
protected:
  void          hoverEnterEvent(QGraphicsSceneHoverEvent* event);
  void          hoverLeaveEvent(QGraphicsSceneHoverEvent* event);
...
};

void myItemGroup:hoverEnterEvent(QGraphicsSceneHoverEvent* event)
{
  printf("hoverEnterEvent called\n");  // This never gets printed!
}
void myItemGroup:hoverLeaveEvent(QGraphicsSceneHoverEvent* event)
{
  printf("hoverLeaveEvent called\n");  // Neither does this.
}

--
 [ signature omitted ] 

Message 2 in thread

On 25 mar 2007, at 18.59, Larry Bristol wrote:

> I need to modify a group of graphics items when the mouse hovers  
> over that
> particular group.  The items are grouped within myItemGroup, a  
> subclass of
> QGraphicsItemGroup.  I have written code for the hover enter and leave
> event handlers, but these never seem to get invoked.
>
> I am obviously overlooking something, but I'm stumped and would  
> appreciate
> some help.  Here is a code snippet to illustrate:
>
> class myItemGroup : public QObject, public QGraphicsItemGroup
> {
>   Q_OBJECT
> ...
> protected:
>   void          hoverEnterEvent(QGraphicsSceneHoverEvent* event);
>   void          hoverLeaveEvent(QGraphicsSceneHoverEvent* event);
> ...
> };
>
> void myItemGroup:hoverEnterEvent(QGraphicsSceneHoverEvent* event)
> {
>   printf("hoverEnterEvent called\n");  // This never gets printed!
> }
> void myItemGroup:hoverLeaveEvent(QGraphicsSceneHoverEvent* event)
> {
>   printf("hoverLeaveEvent called\n");  // Neither does this.
> }
>
bool QGraphicsItem::acceptsHoverEvents () const
Returns true if an item accepts hover events  
(QGraphicsSceneHoverEvent); otherwise, returns false. By default,  
items do not accept hover events.
See also setAcceptsHoverEvents() and setAcceptedMouseButtons().
Have you enabled them?
------
What is a woman that you forsake her, and the hearth fire and the  
home acre,
to go with the old grey Widow Maker.  --Kipling, harp song of the  
Dane women
Tommy Nordgren
tommy.nordgren@xxxxxxxxx



--
 [ signature omitted ] 

Message 3 in thread

Tommy Nordgren wrote:

> bool QGraphicsItem::acceptsHoverEvents () const
> Returns true if an item accepts hover events
> (QGraphicsSceneHoverEvent); otherwise, returns false. By default,
> items do not accept hover events.
> See also setAcceptsHoverEvents() and setAcceptedMouseButtons().
> Have you enabled them?

Nope.  That fixed it.  Thanks, Tommy!

In QtAssistant, setAcceptMouseEvents has a reference to the event handlers
("see hoverEnterEvent, hoverMoveEvent, and hoverLeaveEvent").  It certainly
would be nice if the documentation for the event handlers happened to
mention "see setAcceptsHoverEvents".  :-)

--
 [ signature omitted ] 

Message 4 in thread

Hi,

> In QtAssistant, setAcceptMouseEvents has a reference to the event handlers
> ("see hoverEnterEvent, hoverMoveEvent, and hoverLeaveEvent").  It certainly
> would be nice if the documentation for the event handlers happened to
> mention "see setAcceptsHoverEvents".  :-)

I think that's the case in current snapshots, but also in Qt 4.3.0beta:
http://doc.trolltech.com/4.3-snapshot/qgraphicsitem.html#hoverEnterEvent

--
 [ signature omitted ] 

Message 5 in thread

Dimitri wrote:

> I think that's the case in current snapshots, but also in Qt 4.3.0beta:
> http://doc.trolltech.com/4.3-snapshot/qgraphicsitem.html#hoverEnterEvent

I should have pointed out I am using 4.2.1.  Thanks, Dimitri!  That snapshot
looks good!  Hopefully, I won't *need* that doc change next time, but I
suppose I could experience one of those "senior moments".  <grin>  

--
 [ signature omitted ]