view_widget_->setBackgroundBrush(palette().window());
ui_.picture_widget_->setAttribute(Qt::WA_NoSystemBackground, true);
view_widget_->setBackgroundBrush(palette().window());
ui_.picture_widget_->setAttribute(Qt::WA_NoSystemBackground, true);
To copy to clipboard, switch view to plain text mode
view_widget_ - QGraphicsView
ui_.picture_widget_ - is parent of view_widget_
palette().window() - returns black brush
Code related to other graphicsview initialization:
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setFrameStyle
(QFrame::NoFrame);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setFrameStyle(QFrame::NoFrame);
setTransformationAnchor(QGraphicsView::NoAnchor);
setResizeAnchor(QGraphicsView::NoAnchor);
setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
setCacheMode(QGraphicsView::CacheNone);
To copy to clipboard, switch view to plain text mode
Code related to scene:
graphics_scene_->setItemIndexMethod(QGraphicsScene::NoIndex);
To copy to clipboard, switch view to plain text mode
Then add some (or one) items and zoom to scene bounding rect:
scene_rect = scene()->itemsBoundingRect();
scene_rect = scene()->itemsBoundingRect();
To copy to clipboard, switch view to plain text mode
Then zoom to scene_rect (rect == scene_rect)
Code inside QGraphicsView derived class:
// set scale to 1.0
pt_00 = matrix().map(pt_00);
pt_01 = matrix().map(pt_01);
pt_10 = matrix().map(pt_10);
unity.setWidth(Distance(pt_00, pt_10));
unity.setHeight(Distance(pt_00, pt_01));
scale(1 / unity.width(), 1 / unity.height());
// Find the ideal x / y scaling ratio to fit \a rect in the view.
QRectF viewRect
(0,
0, size
().
width(), size
().
height());
int margin = 2;
viewRect = viewRect.adjusted(margin, margin, -margin, -margin);
QRectF sceneRect
= matrix
().
mapRect(rect
);
qreal xratio = viewRect.width() / sceneRect.width();
qreal yratio = viewRect.height() / sceneRect.height();
xratio = yratio = qMin(xratio, yratio);
scale(xratio, yratio);
centerOn(rect.center());
setSceneRect(rect);
// set scale to 1.0
QPointF pt_00(0, 0);
QPointF pt_01(0, 1);
QPointF pt_10(1, 0);
pt_00 = matrix().map(pt_00);
pt_01 = matrix().map(pt_01);
pt_10 = matrix().map(pt_10);
QSizeF unity;
unity.setWidth(Distance(pt_00, pt_10));
unity.setHeight(Distance(pt_00, pt_01));
scale(1 / unity.width(), 1 / unity.height());
// Find the ideal x / y scaling ratio to fit \a rect in the view.
QRectF viewRect(0, 0, size().width(), size().height());
int margin = 2;
viewRect = viewRect.adjusted(margin, margin, -margin, -margin);
QRectF sceneRect = matrix().mapRect(rect);
qreal xratio = viewRect.width() / sceneRect.width();
qreal yratio = viewRect.height() / sceneRect.height();
xratio = yratio = qMin(xratio, yratio);
scale(xratio, yratio);
centerOn(rect.center());
setSceneRect(rect);
To copy to clipboard, switch view to plain text mode
Also these white lines are excluded from rendering (alsways white, event if graphics item overlaps them) until changing of view zoom by "setSceneRect(rect);"
Also it looks like rounding issue inside qt.
Bookmarks