sceneImage->setPixel( (int)(scenePoint.x()), (int)(scenePoint.y()) ,QColor(R,G,B));
protected: void mousePressEvent(QGraphicsSceneMouseEvent* event) { QPixmap pixmap; addPixmap(pixmap.fromImage(*sceneImage)); }};
C++ (Qt)explicit GraphicsScene(QObject*parent = 0): QGraphicsScene(parent){ sceneImage = new QImage("D:/Qt/Qt5.2.1/Tools/QtCreator/bin/Graphics/lodka.bmp"); QPixmap pixmap; item= addPixmap(pixmap.fromImage(*sceneImage)); } void mousePressEvent(QGraphicsSceneMouseEvent* event){ QPointF scenePoint = event->scenePos(); sceneImage->setPixel( (int)(scenePoint.x()), (int)(scenePoint.y()) ,155); QPixmap pixmap; item->setPixmap(pixmap.fromImage(*sceneImage));}
C++ (Qt)void mousePressEvent(QGraphicsSceneMouseEvent* event){ QPointF scenePoint = event->scenePos(); sceneImage->setPixel( (int)(scenePoint.x()), (int)(scenePoint.y()) ,155); item->setPixmap( QPixmap::fromImage(*sceneImage) );}
C++ (Qt)Item::Item(QGraphicsItem *parent): QGraphicsItem(parent){} Item::~Item(){} void Item::mousePressEvent(QGraphicsSceneMouseEvent* event){ qDebug()<<"mousePressEvent"; event->accept();}
C++ (Qt) GraphicsScene::GraphicsScene(QString path, QObject*parent) : QGraphicsScene(parent){ sceneImage = new QImage(path); QPixmap pixmap; Item* item = (Item *)(addPixmap(pixmap.fromImage(*sceneImage))); } GraphicsScene:: ~GraphicsScene(){ delete sceneImage;}
C++ (Qt) GraphicsScene scene(filepath); QGraphicsView view(&scene); view.show();
C++ (Qt)Item::Item(QGraphicsItem *parent): QGraphicsItem(parent){} Item::~Item(){} void Item::mousePressEvent(QGraphicsSceneMouseEvent* event){ qDebug()<<"mousePressEvent";}
C++ (Qt)class Item1: public QGraphicsItem{public: Item1(QGraphicsItem*parent = 0) :QGraphicsItem(parent),down(false){} QRectF boundingRect() const { return QRectF(0,0,100,70); } void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { painter->setBrush(down ? Qt::red : Qt::green); QPen pen(QBrush(down ? Qt::red : Qt::blue),3, Qt::DotLine); painter->setPen(pen); painter->drawEllipse(boundingRect()); } protected: void mousePressEvent(QGraphicsSceneMouseEvent* event) { if(!down) { down = true; update(); } } void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) { if(event->buttons() == 0) { down = false; update(); } } private: bool down;};
C++ (Qt)GraphicsScene::GraphicsScene(QString path, QObject*parent) : QGraphicsScene(parent){ sceneImage = new QImage(path); QPixmap pixmap; Item* item =(Item *)(addPixmap(pixmap.fromImage(*sceneImage))); addItem(new Item1); } GraphicsScene:: ~GraphicsScene(){ delete sceneImage;}
C++ (Qt)GraphicsScene::GraphicsScene(QString path, QObject*parent) : QGraphicsScene(parent){ sceneImage = new QImage(path); QPixmap pixmap; item = new Item; item->setPixmap(pixmap.fromImage(*sceneImage)); addItem(item); addItem(new Item1);}