#include "mainwindow.h"#include "ui_mainwindow.h"MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ ui->setupUi(this); QGraphicsScene scene(QRectF(-100,-100,640,480)); QGraphicsView *wgt = new QGraphicsView(&scene); ui->vlMain->addWidget(wgt); QGraphicsRectItem* pRect = scene.addRect(0,0,100,100,QPen(Qt::black,3),QBrush(Qt::red)); pRect->setFlags(QGraphicsItem::ItemIsMovable);}
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ ui->setupUi(this); QGraphicsScene scene(QRectF(-100,-100,640,480)); QGraphicsView *wgt = new QGraphicsView(&scene); ui->vlMain->addWidget(wgt); QGraphicsRectItem* pRect = new QGraphicsRectItem(0,0,100,100); pRect->setPen(QPen(Qt::black,3)); pRect->setBrush(QBrush(Qt::red)); pRect->setPos(0,0); pRect->setFlags(QGraphicsItem::ItemIsMovable); scene.addItem(pRect);}
C++ (Qt)#include "mainwindow.h"#include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ ui->setupUi(this); QGraphicsScene *scene = new QGraphicsScene(QRectF(-100,-100,640,480)); QGraphicsView *wgt = new QGraphicsView(scene); ui->vlMain->addWidget(wgt); QGraphicsRectItem* pRect = scene->addRect(0,0,100,100,QPen(Qt::black,3),QBrush(Qt::red)); pRect->setFlags(QGraphicsItem::ItemIsMovable); }