QGraphicsView *view;view=new QGraphicsView(this);view->setGeometry(10,10,200,500);QGraphicsScene scene; scene.addText("Hello, world!"); scene.addEllipse(10,10,100,100); view->setScene(&scene);
QGraphicsScene *scene = new QGraphicsScene; QGraphicsTextItem* p = scene->addText(tr("Virnasdfasd")); p->setFlag(QGraphicsItem::ItemIsMovable); p->setFlag(QGraphicsItem::ItemIsSelectable); ui.graphicsView->setScene(scene); ui.setupUi(this);
scene = new QGraphicsScene;scene->setItemIndexMethod(QGraphicsScene::NoIndex);QPixmap pixmap(100,100);QPainter painter(&pixmap);painter.drawRect(10,10,80,80);QGraphicsPixmapItem * p = scene->addPixmap(pixmap); QGraphicsTextItem* i = scene->addText(tr("Virnasdfasd")); p->setFlag(QGraphicsItem::ItemIsMovable); p->setFlag(QGraphicsItem::ItemIsSelectable); p->setPos(qrand()%int(scene->width()),qrand()%int(scene->height())); i->setFlag(QGraphicsItem::ItemIsMovable); i->setFlag(QGraphicsItem::ItemIsSelectable); i->setPos(qrand()%int(scene->width()),qrand()%int(scene->height())); p->setZValue(2); i->setZValue(1); QGraphicsItem *ball = new QGraphicsEllipseItem(0, 0, 20, 20); timer = new QTimeLine(5000); timer->setFrameRange(0, 100); QGraphicsItemAnimation *animation = new QGraphicsItemAnimation; animation->setItem(ball); animation->setTimeLine(timer); ball->setFlag(QGraphicsItem::ItemIsMovable); ball->setFlag(QGraphicsItem::ItemIsSelectable); for (int i = 0; i < 200; ++i) animation->setPosAt(i / 200.0, QPointF(i, i)); ball->setZValue(3); scene->setSceneRect(0, 0, 250, 250); scene->addItem(ball); timer->start();QGraphicsView *view = new QGraphicsView(this);view->setGeometry(0,0,1280,800);view->setBaseSize(1280,800);view->setScene(scene);