Results 1 to 3 of 3

Thread: QGraphicsLineItem + setAcceptHoverEvents

  1. #1
    Join Date
    Apr 2008
    Posts
    196
    Thanked 8 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    1

    Default QGraphicsLineItem + setAcceptHoverEvents

    Hey @all,

    i'm trying to get the hover effect working for my QGraphicsLineItem object.
    I have subclassed the QGraphicsLineItem class, and in the constructor i wrote:
    Qt Code:
    1. setAcceptHoverEvents(true);
    To copy to clipboard, switch view to plain text mode 

    I implemented the protected functions like below:
    Qt Code:
    1. void Arrow::hoverEnterEvent(QGraphicsSceneHoverEvent * event) {
    2. //QGraphicsLineItem::hoverEnterEvent(event);
    3. qDebug() << "void Arrow::hoverEnterEvent(QGraphicsSceneHoverEvent * event)";
    4. pen().setColor(QColor(204, 0, 255, 76));
    5. }
    6.  
    7. void Arrow::hoverLeaveEvent(QGraphicsSceneHoverEvent * event) {
    8. qDebug() << "void Arrow::hoverLeaveEvent(QGraphicsSceneHoverEvent * event)";
    9. pen().setColor(myColor);
    10. }
    To copy to clipboard, switch view to plain text mode 

    But when i come over the line with my mouse pointer the functions doesn't be executed?

    What i'am doing wrong? Can anybody help me.

    Regards
    NoRUlez

  2. #2
    Join Date
    Apr 2008
    Posts
    196
    Thanked 8 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    1

    Default Re: QGraphicsLineItem + setAcceptHoverEvents

    I forgot to say, I'm using QT 4.4.0 under Windows XP

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QGraphicsLineItem + setAcceptHoverEvents

    Works for me. Just notice that you can't alter the pen like that (you're modifying a copy of the pen so the original pen doesn't change):

    Qt Code:
    1. // pen().setColor(myColor); // <-- wrong
    2. setPen(QPen(myColor)); // do something like this instead
    3. // or
    4. QPen p = pen();
    5. p.setColor(myColor);
    6. setPen(p);
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

Similar Threads

  1. Newbie needs advice - QGraphicsLineItem
    By Seth in forum Newbie
    Replies: 4
    Last Post: 30th May 2007, 08:23

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.