QGraphicsItem And QGraphicsScene
-
Hello Friends And Qt Experts
I am facing the problem B/W
QGraphicsItem
AndQGraphicsScene
follow my code
.h Fileclass Custome_Scene : public QGraphicsScene { Q_OBJECT public: Custome_Scene(QObject* parent = 0); void mouseMoveEvent(QGraphicsSceneMouseEvent* mouseEvent) override; void mousePressEvent(QGraphicsSceneMouseEvent* mouseEvent) override; void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* mouseEvent) override; }
.cpp File
Custome_Scene::Custome_Scene(QObject *parent) { } void Custome_Scene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent) { qDebug() << mouseEvent->scenePos(); } void Custome_Scene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) { } void Custome_Scene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *mouseEvent) { }
As you see my code
when i try to get my current position of my mouse fromQGraphicsScene
it will work finebut when i Add Any
QGraphicsItem
in myCustome_Scene
that timeQGraphicsItem
can be Movable or Selectablefollow my code for Item Add
Custome_Scene *customescene = new Custome_Scene (); QGraphicsRectItem *Item_Rect = new QGraphicsRectItem(); Item_Rect->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); Item_Rect->setRect(10,10,100,100); Item_Rect->setZValue(1); Item_Rect->setVisible(true); customescene->addItem(Item_Rect);
-
@Ketan__Patel__0011
I have tried to understand what you are saying/your problem is but I do not. In principle your code looks fine. So what is the question, can you rephrase it? -
@JonB
Thanks You For ReplyAs You see my code
i was add RectangleItem in myCustome_Scene
@Ketan__Patel__0011 said in QGraphicsItem And QGraphicsScene:
Item_Rect->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
Accoranding to this my
Item_Rect
should be movable or selectable in myCustome_Scene
but i can handle it.i can't select or move over the my
Custome_Scene
. -
@Ketan__Patel__0011 said in QGraphicsItem And QGraphicsScene:
mousePressEvent
Basic c++ - if you override a function and also want the functionality of the base class you should also call the base class implementation of this function.