PDA

View Full Version : White Lines in graphicsview



nicolas1
16th November 2008, 13:46
Hello,

I have changed backgroung in QGraphicsView object to black (non white) and in some cases (not sure what exactly) there are occasionaly 2 white lines appears: on the most right and most bottom of 1 pixel width. Any idea why this happens and how to avoid this?


Thnaks

wysota
16th November 2008, 17:18
We'd have to see some compilable code that reproduces the problem.

nicolas1
17th November 2008, 00:53
view_widget_->setBackgroundBrush(palette().window());

ui_.picture_widget_->setAttribute(Qt::WA_NoSystemBackground, true);


view_widget_ - QGraphicsView
ui_.picture_widget_ - is parent of view_widget_

palette().window() - returns black brush

Code related to other graphicsview initialization:


setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOf f);

setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff) ;

setFrameStyle(QFrame::NoFrame);

setTransformationAnchor(QGraphicsView::NoAnchor);

setResizeAnchor(QGraphicsView::NoAnchor);

setViewportUpdateMode(QGraphicsView::FullViewportU pdate);

setCacheMode(QGraphicsView::CacheNone);



Code related to scene:


graphics_scene_->setItemIndexMethod(QGraphicsScene::NoIndex);



Then add some (or one) items and zoom to scene bounding rect:



scene_rect = scene()->itemsBoundingRect();



Then zoom to scene_rect (rect == scene_rect)
Code inside QGraphicsView derived class:


// 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);


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.

wysota
17th November 2008, 00:59
Well... this is hardly compilable :) How about a complete project I can compile, run and see the same problem you see? Your problem is probably due to setting NoSystemBackground, but it could be something else. Why did you set this attribute? Because I don't think it is meant for cases such as the one as yours.

nicolas1
17th November 2008, 01:08
Because of flickering. Window flickers once, on initial updating. It is not critical but nasty, when window intended background is black and it flickers white...

Hm, it is easy to reproduce by taking QGraphicsView Qt example and change related code...

removed WA_NoSystemBackground of parent widget. this did not help. I think enough just to change background of QGraphicsView

wysota
17th November 2008, 08:52
So maybe it would be better to remove this flickering using proper methods? :)

Please provide compilable code we can simply download, unpack, write qmake && make and execute.

nicolas1
20th November 2008, 06:05
See attached file. "images" subdir is required. You can find it from Qt example named "diagramscene".
Testing:
1) add several items
2) set 150% zoom level
3) resize window

Lines will appear.

Lines appear when "setCacheMode(QGraphicsView::CacheBackground);"