PDA

View Full Version : QGraphicsLineItem + setAcceptHoverEvents



NoRulez
7th May 2008, 19:02
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:


setAcceptHoverEvents(true);


I implemented the protected functions like below:


void Arrow::hoverEnterEvent(QGraphicsSceneHoverEvent * event) {
//QGraphicsLineItem::hoverEnterEvent(event);
qDebug() << "void Arrow::hoverEnterEvent(QGraphicsSceneHoverEvent * event)";
pen().setColor(QColor(204, 0, 255, 76));
}

void Arrow::hoverLeaveEvent(QGraphicsSceneHoverEvent * event) {
qDebug() << "void Arrow::hoverLeaveEvent(QGraphicsSceneHoverEvent * event)";
pen().setColor(myColor);
}


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

NoRulez
7th May 2008, 19:02
I forgot to say, I'm using QT 4.4.0 under Windows XP

jpn
13th May 2008, 12:13
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):


// pen().setColor(myColor); // <-- wrong
setPen(QPen(myColor)); // do something like this instead
// or
QPen p = pen();
p.setColor(myColor);
setPen(p);