MainWindow
::MainWindow(QWidget *parent
){
scene->setSceneRect(0, 0, 1024, 768);
QGraphicsRectItem *rect1
= scene
->addRect
(scene
->width
() / 4, scene
->height
() / 4,
10,
10);
QGraphicsRectItem *rect2
= scene
->addRect
(scene
->width
() / 3, scene
->height
() / 3,
20,
20);
QGraphicsRectItem *rect3
= scene
->addRect
(scene
->width
() / 2, scene
->height
() / 2,
30,
30);
qDebug() << rect1->pos() << ", " << rect2->pos() << ", " << rect3->pos(); // 3x QPointF(0, 0) -- fine
qDebug() << rect1->scenePos() << ", " << rect2->scenePos() << ", " << rect3->scenePos(); // 3x QPointF(0, 0) -- what?
this->setCentralWidget(view);
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
scene = new QGraphicsScene();
scene->setSceneRect(0, 0, 1024, 768);
QGraphicsRectItem *rect1 = scene->addRect(scene->width() / 4, scene->height() / 4, 10, 10);
QGraphicsRectItem *rect2 = scene->addRect(scene->width() / 3, scene->height() / 3, 20, 20);
QGraphicsRectItem *rect3 = scene->addRect(scene->width() / 2, scene->height() / 2, 30, 30);
qDebug() << rect1->pos() << ", " << rect2->pos() << ", " << rect3->pos(); // 3x QPointF(0, 0) -- fine
qDebug() << rect1->scenePos() << ", " << rect2->scenePos() << ", " << rect3->scenePos(); // 3x QPointF(0, 0) -- what?
view = new QGraphicsView(scene, this);
this->setCentralWidget(view);
}
To copy to clipboard, switch view to plain text mode
Bookmarks