Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Capturing hover events for a QGraphicsRectItem
Forum Updated to NodeBB v4.3 + New Features

Capturing hover events for a QGraphicsRectItem

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 368 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hellozee
    wrote on last edited by
    #1

    Did setAcceptHoverEvents(true) in the constructor and implemented,

    void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
    void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
    void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
    

    But still the QGraphicsRectItem is not capturing the hover events? Am I missing something?

    BoundingRectItem::BoundingRectItem()
    {
        setFlag(QGraphicsItem::ItemIsMovable);
        _transformMode = false;
        _width         = 0;
        _height        = 0;
        setAcceptHoverEvents(true);
    }
    ...
    ...
    void BoundingRectItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
    {
        event->accept();
        qDebug() << "yeah";
    }
    
    void BoundingRectItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
    {
        event->accept();
        qDebug() << "yeah";
    }
    
    void BoundingRectItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
    {
        event->accept();
        qDebug() << "yeah";
    }
    

    Here is the complete source and the header file for the implemented QGraphicsRectItem

    raven-worxR 1 Reply Last reply
    0
    • H hellozee

      Did setAcceptHoverEvents(true) in the constructor and implemented,

      void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
      void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
      void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
      

      But still the QGraphicsRectItem is not capturing the hover events? Am I missing something?

      BoundingRectItem::BoundingRectItem()
      {
          setFlag(QGraphicsItem::ItemIsMovable);
          _transformMode = false;
          _width         = 0;
          _height        = 0;
          setAcceptHoverEvents(true);
      }
      ...
      ...
      void BoundingRectItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
      {
          event->accept();
          qDebug() << "yeah";
      }
      
      void BoundingRectItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
      {
          event->accept();
          qDebug() << "yeah";
      }
      
      void BoundingRectItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
      {
          event->accept();
          qDebug() << "yeah";
      }
      

      Here is the complete source and the header file for the implemented QGraphicsRectItem

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @hellozee
      you need to make sure that also boundingRect() shape() returns a plausible value for your custom item
      So either you reimplement this method yourself or (suggested) you need to set the rect also to the base class (QGraphicsRectItem::setRect())

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved