PDA

View Full Version : mouse events



xyzt
23rd March 2008, 10:43
in the documentation there's a sample that demonstrates Graphics View Framework. The class DiagramItem inherits QGraphicsPolygonItem but it doesn't override the mouse events, so how can it answer to the mouse events?
here's the code:(copied from the QT Documentation):


class DiagramItem : public QGraphicsPolygonItem
{
public:
enum { Type = UserType + 15 };
enum DiagramType { Step, Conditional, StartEnd, Io };

DiagramItem(DiagramType diagramType, QMenu *contextMenu,
QGraphicsItem *parent = 0, QGraphicsScene *scene = 0);

void removeArrow(Arrow *arrow);
void removeArrows();
DiagramType diagramType() const
{ return myDiagramType; }
QPolygonF polygon() const
{ return myPolygon; }
void addArrow(Arrow *arrow);
QPixmap image() const;
int type() const
{ return Type;}

protected:
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
QVariant itemChange(GraphicsItemChange change, const QVariant &value);

private:
DiagramType myDiagramType;
QPolygonF myPolygon;
QMenu *myContextMenu;
QList<Arrow *> arrows;
};

wysota
23rd March 2008, 11:04
Base implementation of mouse events in QGraphicsItem handles that. And also both the view and the scene can handle events for items.

xyzt
23rd March 2008, 11:12
Base implementation of mouse events in QGraphicsItem handles that. And also both the view and the scene can handle events for items.

OK,base class handles if the child didn't implemented it but what is done when the event is handled? shouldn't the DiagramItem class implement it to do a custom job?

wysota
23rd March 2008, 11:14
If you want to change the original behaviour, then of course, yes.