#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->graphicsView->setScene(scene);
scene->setSceneRect(0,0,400,400);
// Create the first red rectangle on the graphic scene
rect1->setRect(10,50,100,50);
rect1
->setBrush
(QBrush(Qt
::red));
scene->addItem(rect1);
// And create a second blue rectangle on the graphic scene
rect2->setRect(150,100,115,75);
rect2
->setBrush
(QBrush(Qt
::blue));
scene->addItem(rect2);
}
#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);
}
To copy to clipboard, switch view to plain text mode
Bookmarks