Hi,
II'm trying to move a GraphicsItem on a GraphicsScene using moveBy()Function but nothing moves on the screen , may someone help me to achieve this ?
Thanks in advance
here is the Programmcode i tried to write :
-------
{
public:
};
p.setWidth(2);
setPen(p);
setBrush(brush);
setRect()x,y,100,60;
show();
}
class Container: public QGraphicsRectItem
{
public:
Container(QGraphicsItem* parent=0, intx, int y);
};
Container::Container(QGraphicsItem* parent, intx=0, int y=0): QGraphicsRectItem(parent)
{QColor color (0,0,100);
QPen p(color);
p.setWidth(2);
QBrush brush(QColor(0,160,0));
setPen(p);
setBrush(brush);
setRect()x,y,100,60;
show();
}
To copy to clipboard, switch view to plain text mode
--------
#include"Container.h"
{
public:
Container*container;
};
{
setBackgroundBrush(brush);
}
#include"Container.h"
class Scene: public QGraphicsScene
{
public:
Scene(QWidget* parent=0);
Container*container;
};
Scene::Scene(QWidget* parent):QGraphicsScene(parent)
{
QBrush brush(QColor(180,180,220), Qt::Dense4Pattern);
setBackgroundBrush(brush);
}
To copy to clipboard, switch view to plain text mode
--------
mainGui class
#include"include/gui/mainGui.h"
#include"include/gui/Scene.h"
#include"include/gui/container.h"
{
Q_OBJECT
public:
private:
};
{
scene=newScene(this);
Container*c1= new Container(0,0,0);
// I want the item to move step by step after any 1000 ms on the Screen
int x=event->pos().x();
int y=event->pos().y();
c1->moveBy((qreal)x,(qreal)y);
startTimer(1000);
c1->addItem(c1);
scene->addLine(-5, -200, -5, 200);
scene->addLine(105, -200,105, 200);
scene->advance();
layout->addWidget(view);
setLayou(layout);
view->show();
}
#include"include/gui/mainGui.h"
#include"include/gui/Scene.h"
#include"include/gui/container.h"
class MainGui:public QWidget
{
Q_OBJECT
public:
MainGui(QWidget*parent=0);
private:
QGraphicsScene *scene;
};
MainGui::MainGui(QWidget *parent):QWidget(parent)
{
scene=newScene(this);
Container*c1= new Container(0,0,0);
// I want the item to move step by step after any 1000 ms on the Screen
QMoveEvent *event;
int x=event->pos().x();
int y=event->pos().y();
c1->moveBy((qreal)x,(qreal)y);
startTimer(1000);
c1->addItem(c1);
scene->addLine(-5, -200, -5, 200);
scene->addLine(105, -200,105, 200);
scene->advance();
QGraphicsView *view =new QGraphicsView (scene);
QGridLayout *layout= new QGridLayout();
layout->addWidget(view);
setLayou(layout);
view->show();
}
To copy to clipboard, switch view to plain text mode
Bookmarks