Thank you very much, Spitfire. Unfortunately I still don't get it done, to "know and use" the viewable portion of the scene.
I think there will probably be a very stupid beginner's mistake either in the setup of widget, layout, scene & view, or in their calling order.
I tried so many changes that I start to be really confused.
The code I use:
MainWindow::MainWindow()
{
createActions();
createMenus();
setWindowTitle(tr("Title"));
statusBar()->showMessage(tr("Ready"));
setUnifiedTitleAndToolBarOnMac(true);
this->showMaximized();
scene=new QGraphicScene(this);
setCentralWidget(widget);
widget->setLayout(layout);
layout->addWidget(view);
this->scene->setSceneRect(this->view->rect());
rectItem->setRect(this->view->mapToScene(this->view->rect()).boundingRect());
//rectItem->setRect(0,0,scene->width(),scene->height());
scene->addItem(rectItem);
rectItem->setZValue(1000);
rectItem
->setBrush
(QBrush(Qt
::black,Qt
::SolidPattern));
view
->setRenderHints
(QPainter::HighQualityAntialiasing|QPainter
::TextAntialiasing);
view->setInteractive(true);
view->setMouseTracking(true);
//view->scale(1,1);
//scene->setBackgroundBrush(this->backgroundPic.scaled(screenRect.width(),screenRect.height(),Qt::IgnoreAspectRatio,Qt::SmoothTransformation));
[...put other stuff onto scene...]
}
MainWindow::MainWindow()
{
createActions();
createMenus();
setWindowTitle(tr("Title"));
statusBar()->showMessage(tr("Ready"));
setUnifiedTitleAndToolBarOnMac(true);
this->showMaximized();
scene=new QGraphicScene(this);
view = new QGraphicsView(scene);
QHBoxLayout *layout = new QHBoxLayout;
QWidget *widget = new QWidget;
widget->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
setCentralWidget(widget);
widget->setLayout(layout);
layout->addWidget(view);
this->scene->setSceneRect(this->view->rect());
QGraphicsRectItem* rectItem = new QGraphicsRectItem();
rectItem->setRect(this->view->mapToScene(this->view->rect()).boundingRect());
//rectItem->setRect(0,0,scene->width(),scene->height());
scene->addItem(rectItem);
rectItem->setZValue(1000);
rectItem->setBrush(QBrush(Qt::black,Qt::SolidPattern));
view->setRenderHints(QPainter::HighQualityAntialiasing|QPainter::TextAntialiasing);
view->setDragMode(QGraphicsView::ScrollHandDrag);
view->setInteractive(true);
view->setMouseTracking(true);
//view->scale(1,1);
//scene->setBackgroundBrush(this->backgroundPic.scaled(screenRect.width(),screenRect.height(),Qt::IgnoreAspectRatio,Qt::SmoothTransformation));
[...put other stuff onto scene...]
}
To copy to clipboard, switch view to plain text mode
The result should be a black rectangle covering the entire screen. In fact, the rectangle it is occupying a much smaller size, which I can't understand for the life of me... (see JPG)
Bookmarks