C++ (Qt)setFlag(QGraphicsItem::ItemIsMovable, true);
C++ (Qt)#include <QGraphicsView>#include <QGraphicsScene>#include <QGraphicsRectItem>#include <QApplication> int main(int argc, char *argv[]){ QApplication a(argc, argv); QGraphicsView view; QGraphicsScene *scene = new QGraphicsScene(); view.setScene(scene); scene->addRect(QRectF(-100.0, -100.0, 50.0, 50.0)); scene->addRect(QRectF(0.0, -100.0, 50.0, 50.0)); scene->addRect(QRectF(-100.0, 0.0, 50.0, 50.0)); scene->addRect(QRectF(0.0, 0.0, 50.0, 50.0)); scene->addRect(QRectF(100.0, 100.0, 50.0, 50.0)); scene->addRect(QRectF(0.0, 100.0, 50.0, 50.0)); scene->addRect(QRectF(100.0, 0.0, 50.0, 50.0)); scene->addRect(QRectF(-100.0, 100.0, 50.0, 50.0)); scene->addRect(QRectF(100.0, -100.0, 50.0, 50.0)); view.show(); return a.exec();}
setFlag(QGraphicsItem::ItemIsMovable, true);
C++ (Qt)QGraphicsRectItem *item = new QGraphicsRectItem();item->setFlag(QGraphicsItem::ItemIsMovable, true);item->setRect(QRectF(-100.0, -100.0, 50.0, 50.0)); scene->addItem(item);
item->setFlag(QGraphicsItem::ItemIsMovable, true);
item->setRect(QRectF(-100.0, -100.0, 50.0, 50.0));
scene->addItem(item);