PDA

View Full Version : How can I re-size the QGraphicViewItem using mouse



rooter
23rd October 2017, 21:24
How can I change the QGraphicView Item size using mouse.this code generate the 2 rectangles,how can I change the sizes of those rectangles using mouse.
This image shows my expected result.

12639




#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);

scene = new QGraphicsScene();
ui->graphicsView->setScene(scene);
scene->setSceneRect(0,0,400,400);

// Create the first red rectangle on the graphic scene
QGraphicsRectItem *rect1 = new QGraphicsRectItem();
rect1->setRect(10,50,100,50);
rect1->setBrush(QBrush(Qt::red));
rect1->setPen(QPen(QBrush(Qt::black),2));
scene->addItem(rect1);

// And create a second blue rectangle on the graphic scene
QGraphicsRectItem *rect2 = new QGraphicsRectItem();
rect2->setRect(150,100,115,75);
rect2->setBrush(QBrush(Qt::blue));
rect2->setPen(QPen(QBrush(Qt::black),2));
scene->addItem(rect2);
}