Results 1 to 6 of 6

Thread: MouseMoveEvent deal between QGraphicsView and QGraphicsItem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 334 Times in 317 Posts

    Default Re: MouseMoveEvent deal between QGraphicsView and QGraphicsItem

    You will need to store a variable for color.
    Say you have QColor m_color in your graphics item class.
    Then in paint event you do the following -
    Qt Code:
    1. paint()
    2. {
    3. QColor color = m_color;
    4. if(option->state & QStyle::State_MouseOver)
    5. color = m_color.dark();
    6.  
    7.  
    8. painter->fillRect(boundingRect(),color);
    9. }
    To copy to clipboard, switch view to plain text mode 

    thats it, and now when you hover over the item, it will become dark.
    Remember to set QGraphicsItem::setAcceptHoverEvents to true

  2. The following user says thank you to aamer4yu for this useful post:

    Casper14 (22nd July 2014)

Similar Threads

  1. QGraphicsView, QGraphicsItem, QGraphicsScene
    By Shuchi Agrawal in forum Newbie
    Replies: 10
    Last Post: 23rd March 2011, 21:50
  2. destruction of QGraphicsItem
    By killkolor in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2009, 11:31
  3. Replies: 2
    Last Post: 12th February 2009, 10:53
  4. (QT4.2-RC1) QGraphicsScene QGraphicsView QGraphicsItem
    By antonio.r.tome in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2006, 11:56

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
  •  
Qt is a trademark of The Qt Company.