Results 1 to 4 of 4

Thread: Highlight QGraphicsItem during connection.

  1. #1
    Join Date
    May 2013
    Posts
    24
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Highlight QGraphicsItem during connection.

    Hi,

    I'm playing around with the Diagramscene example provided with QT. What I would like to accomplish is to highlight the DiagramItem when connecting two boxes (e.g. process box).

    I have tried to implement the hoverEnter/hoverLeave event and it seems to work for the box I start the connect. When I enter the other box while dragging a line no events are passed to the other DiagramItem. When I release the mousebutton I get hoverEnter events.

    How can I make this work?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Highlight QGraphicsItem during connection.

    It depends how you implemented what you have so far.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    May 2013
    Posts
    24
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Highlight QGraphicsItem during connection.

    I started with Diagramscene example.
    In DiagramItem.cpp/.h I override:
    Qt Code:
    1. void DiagramItem::hoverEnterEvent(QGraphicsSceneHoverEvent * event)
    2. {
    3. qDebug() << (int)this << ": Hover enter event";
    4. m_color = Qt::cyan;
    5. QGraphicsPolygonItem::hoverEnterEvent(event);
    6. }
    7.  
    8. void DiagramItem::hoverLeaveEvent(QGraphicsSceneHoverEvent * event)
    9. {
    10. qDebug() << (int)this << ": Hover leave event";
    11. m_color = Qt::black;
    12. QGraphicsPolygonItem::hoverLeaveEvent(event);
    13. }
    14.  
    15. void DiagramItem::paint(QPainter * painter, const QStyleOptionGraphicsItem * option,
    16. QWidget * widget)
    17. {
    18. if (option->state & QStyle::State_MouseOver )
    19. {
    20. qDebug() << (int)this << "Mouse over!";
    21. }
    22.  
    23. QPen p = pen();
    24. p.setColor(m_color);
    25. setPen(p);
    26. qDebug() << m_color;
    27. QGraphicsPolygonItem::paint(painter, option, widget);
    28. }
    To copy to clipboard, switch view to plain text mode 

    in void DiagramScene::mousePressEvent(QGraphicsSceneMouseE vent *mouseEvent) I added item->setAcceptHoverEvents(true);

  4. #4
    Join Date
    May 2013
    Posts
    24
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Highlight QGraphicsItem during connection.

    Ok, I solved it.
    Instead of putting code in hoverenter/hoverleave of the DiagramItem, I put the code in scene's mouseMoveEvent. To know wich item to highlight I reused some of the code in mouseReleseEvent.

Similar Threads

  1. Replies: 0
    Last Post: 11th November 2011, 19:18
  2. Replies: 7
    Last Post: 29th November 2010, 19:20
  3. Replies: 1
    Last Post: 2nd April 2010, 06:42
  4. Casting QGraphicsItem child from QGraphicsItem
    By patrik08 in forum Qt Programming
    Replies: 3
    Last Post: 29th August 2008, 15:37
  5. Replies: 2
    Last Post: 28th June 2008, 16:31

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.