//the following events are for the items visual appearance
//addded by sajjad
//the following events are for the items visual appearance
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
//addded by sajjad
void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
To copy to clipboard, switch view to plain text mode
/////////////////////////////////////////
{
update();
}
{
update();
}
{
if(event->modifiers() == Qt::ControlModifier)
{
update();
}
}
{
if(event->modifiers() == Qt::ControlModifier)
{
update();
}
}
{
update();
}
/////////////////////////////////////////
void Node::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
update();
QGraphicsItem::mousePressEvent(event);
}
void Node::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
update();
QGraphicsItem::mouseReleaseEvent(event);
}
void Node::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
if(event->modifiers() == Qt::ControlModifier)
{
update();
QGraphicsItem::hoverMoveEvent(event);
}
}
void Node::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
if(event->modifiers() == Qt::ControlModifier)
{
update();
QGraphicsItem::hoverEnterEvent(event);
}
}
void Node::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
update();
QGraphicsItem::hoverMoveEvent(event);
}
To copy to clipboard, switch view to plain text mode
/////////////////////////////////////////////
{
painter->setPen(Qt::NoPen);
painter->setBrush(Qt::darkGray);
painter->drawEllipse(-7, -7, 20, 20);
if (option
->state
& QStyle::State_Sunken) {
//button pressed mode
gradient.setCenter(3, 3);
gradient.setFocalPoint(3, 3);
gradient.
setColorAt(1,
QColor(Qt
::yellow).
light(120));
gradient.
setColorAt(0,
QColor(Qt
::darkYellow).
light(120));
//gradient.setColorAt(0, QColor(Qt::red).light(120));
//qDebug() << "Sunken state" << endl;
std::cout << "It is in the sunken state" << std::endl;
}
else if(option
->state
& QStyle::State_MouseOver) {
gradient.setColorAt(0, Qt::red);
gradient.setColorAt(1, Qt::darkYellow);
std::cout << "It is in the mosue over state" << std::endl;
}
else if(option
->state
& (!QStyle::State_Sunken & QStyle::State_MouseOver)) {
gradient.setColorAt(0, Qt::yellow);
gradient.setColorAt(1, Qt::darkYellow);
}
else
{
gradient.setColorAt(0, Qt::yellow);
gradient.setColorAt(1, Qt::darkYellow);
std::cout << "It is in the initial state" << std::endl;
}
painter->setBrush(gradient);
painter
->setPen
(QPen(Qt
::black,
0));
painter->drawEllipse(-10, -10, 20, 20);
}
void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
{
painter->setPen(Qt::NoPen);
painter->setBrush(Qt::darkGray);
painter->drawEllipse(-7, -7, 20, 20);
QRadialGradient gradient(-3, -3, 10);
if (option->state & QStyle::State_Sunken)
{
//button pressed mode
gradient.setCenter(3, 3);
gradient.setFocalPoint(3, 3);
gradient.setColorAt(1, QColor(Qt::yellow).light(120));
gradient.setColorAt(0, QColor(Qt::darkYellow).light(120));
//gradient.setColorAt(0, QColor(Qt::red).light(120));
//qDebug() << "Sunken state" << endl;
std::cout << "It is in the sunken state" << std::endl;
}
else if(option->state & QStyle::State_MouseOver)
{
gradient.setColorAt(0, Qt::red);
gradient.setColorAt(1, Qt::darkYellow);
std::cout << "It is in the mosue over state" << std::endl;
}
else if(option->state & (!QStyle::State_Sunken & QStyle::State_MouseOver))
{
gradient.setColorAt(0, Qt::yellow);
gradient.setColorAt(1, Qt::darkYellow);
}
else
{
gradient.setColorAt(0, Qt::yellow);
gradient.setColorAt(1, Qt::darkYellow);
std::cout << "It is in the initial state" << std::endl;
}
painter->setBrush(gradient);
painter->setPen(QPen(Qt::black, 0));
painter->drawEllipse(-10, -10, 20, 20);
}
To copy to clipboard, switch view to plain text mode
Bookmarks