Thanks for the answer.
but I now the problem, I have to draw in the graphicscene and not in der item...
But I tried another way without solution: Now I try to move a ellipse that is in the scene, but in my program there's a small mistake(I think), what I don't see...
I think it's a mistake in the main function?!
Please help...
main.cpp
int main(int argc,char **argv)
{
StarItem item(100,100,10,10);
scene.addItem(&item);
view.setGeometry(100, 100, 500, 500);
view.setScene(&scene);
view.show();
return app.exec();
}
int main(int argc,char **argv)
{
QApplication app(argc,argv);
QGraphicsScene scene;
QGraphicsView view;
StarItem item(100,100,10,10);
scene.addItem(&item);
view.setGeometry(100, 100, 500, 500);
view.setScene(&scene);
view.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
staritem.h
{
public:
protected:
};
class StarItem : public QGraphicsEllipseItem
{
public:
StarItem (int x,int y,int w,int h) : QGraphicsEllipseItem (x,y,w,h) {}
protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent *e);
};
To copy to clipboard, switch view to plain text mode
staritem.cpp
{
setRect((e->scenePos().x()),(e->scenePos().y()),10,10);
}
void StarItem::mouseMoveEvent(QGraphicsSceneMouseEvent *e)
{
setRect((e->scenePos().x()),(e->scenePos().y()),10,10);
}
To copy to clipboard, switch view to plain text mode
Thanks for every answer.
Bookmarks