Hi, this is a "spin-off" question of the thread here.
To keep control over available screen space I want to know the visible part of a QGraphicsScene - in scene coordinates.
To verify that my information is correct, I want to draw a black rectangle all over the visble scene area. Of course, the rectangle is just for testing purposes :-)
I've tried the following approach:
MainWindow::MainWindow()
{
this->showMaximized();
scene=new QGraphicScene(this);
//widget->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
setCentralWidget(widget);
widget->setLayout(layout);
layout->addWidget(view);
this->scene->setSceneRect(this->view->rect());
rectItem->setRect(this->view->mapToScene(this->view->rect()).boundingRect());
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);
[...put other stuff onto scene...]
}
MainWindow::MainWindow()
{
this->showMaximized();
scene=new QGraphicScene(this);
view = new QGraphicsView(scene);
QWidget *widget = new QWidget;
QHBoxLayout *layout = new QHBoxLayout;
//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());
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);
[...put other stuff onto scene...]
}
To copy to clipboard, switch view to plain text mode
I'd love to see a black screen now - but the RectItem is much smaller than expected - thus I have quite obviously made a mistake in getting the size of the viewable area...
Only the code seems logical and correct to me.
Desired result: desiredResult.jpg
Actual result: viewportRecNewTry.jpg
What am I doing wrong?
Bookmarks