Results 1 to 7 of 7

Thread: White Lines in graphicsview

  1. #1
    Join Date
    Jun 2008
    Posts
    35
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default White Lines in graphicsview

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: White Lines in graphicsview

    We'd have to see some compilable code that reproduces the problem.

  3. #3
    Join Date
    Jun 2008
    Posts
    35
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: White Lines in graphicsview

    Qt Code:
    1. view_widget_->setBackgroundBrush(palette().window());
    2.  
    3. 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:
    Qt Code:
    1. setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    2.  
    3. setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    4.  
    5. setFrameStyle(QFrame::NoFrame);
    6.  
    7. setTransformationAnchor(QGraphicsView::NoAnchor);
    8.  
    9. setResizeAnchor(QGraphicsView::NoAnchor);
    10.  
    11. setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
    12.  
    13. setCacheMode(QGraphicsView::CacheNone);
    To copy to clipboard, switch view to plain text mode 


    Code related to scene:
    Qt Code:
    1. 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:

    Qt Code:
    1. 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:
    Qt Code:
    1. // set scale to 1.0
    2. QPointF pt_00(0, 0);
    3. QPointF pt_01(0, 1);
    4. QPointF pt_10(1, 0);
    5.  
    6. pt_00 = matrix().map(pt_00);
    7. pt_01 = matrix().map(pt_01);
    8. pt_10 = matrix().map(pt_10);
    9.  
    10. QSizeF unity;
    11.  
    12. unity.setWidth(Distance(pt_00, pt_10));
    13. unity.setHeight(Distance(pt_00, pt_01));
    14.  
    15.  
    16. scale(1 / unity.width(), 1 / unity.height());
    17.  
    18. // Find the ideal x / y scaling ratio to fit \a rect in the view.
    19. QRectF viewRect(0, 0, size().width(), size().height());
    20.  
    21. int margin = 2;
    22.  
    23. viewRect = viewRect.adjusted(margin, margin, -margin, -margin);
    24.  
    25. QRectF sceneRect = matrix().mapRect(rect);
    26.  
    27. qreal xratio = viewRect.width() / sceneRect.width();
    28. qreal yratio = viewRect.height() / sceneRect.height();
    29.  
    30. xratio = yratio = qMin(xratio, yratio);
    31.  
    32. scale(xratio, yratio);
    33.  
    34. centerOn(rect.center());
    35.  
    36. 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.
    Last edited by nicolas1; 17th November 2008 at 01:07.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: White Lines in graphicsview

    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.

  5. #5
    Join Date
    Jun 2008
    Posts
    35
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default

    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
    Last edited by wysota; 17th November 2008 at 08:49. Reason: Please edit your posts instead of writing new ones...

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: White Lines in graphicsview

    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.

  7. #7
    Join Date
    Jun 2008
    Posts
    35
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: White Lines in graphicsview

    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); "
    Attached Files Attached Files

Similar Threads

  1. use Qpainter to draw lines + problem in my painter
    By ReSu in forum Qt Programming
    Replies: 4
    Last Post: 5th March 2008, 16:44

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.