Hi, I have a class named "Graphics" which is derived from "QGraphicsItem" and represents a small green rectangle:
Code:
#include <QtGui> #include <QPainter> #include <iostream> #include <QColor> #include "Graphics.hpp" Graphics::Graphics(): color(qrand() % 256, qrand() % 256, qrand() % 256) { setCursor(Qt::OpenHandCursor); } { } { Q_UNUSED(option); Q_UNUSED(widget); painter->setPen(Qt::NoPen); painter->setBrush(Qt::green); painter->drawRect(0, 0, 10, 20); } { }
But now, when clicked on a rectangle, I want it's color to change to red. But I have read that there is no such thing as a "repaint" methode. Anoyne who can help me, and tell me how to get the clicked rectangle red? I have no idea what to do within the mouseEvent