Results 1 to 7 of 7

Thread: Graphics View : too many lines

  1. #1
    Join Date
    Sep 2009
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Graphics View : too many lines

    Hi,

    In my project I need to put lots of lines into the graphics scene. Thousands of graphicsscene::addLine decrease the program's performance dramatically as you can guess.
    I don't know why but polyline doesn't exist for graphics scene and I need graphics view architecture since the project will be an interactive one.

    Any ideas?

    Thanks.

  2. #2
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: Graphics View : too many lines

    Do you need to interact with them? if not, you can draw them in the paint event instead of creating QGraphicsLineItem.

  3. #3
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Graphics View : too many lines

    Quote Originally Posted by natnan View Post
    I don't know why but polyline doesn't exist for graphics scene
    Take a look at the QGraphicsPathItem and QGraphicsPolygonItem.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  4. #4
    Join Date
    Sep 2009
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Graphics View : too many lines

    @jano_alex_es
    Yes, I need to interact with them.


    I'm already using qpolygonItem in my project as well. Polygons merge the first point and the last point, something I don't want.
    I'm guessing path does the same as far as I've read.

  5. #5
    Join Date
    Jan 2010
    Posts
    11
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Graphics View : too many lines

    Just curious, when you say 'thousands', do you mean 1000, 10000, 100000? For the project I'm working on, I've actually been able to display somewhere around 10,000 QGraphicsItems at a time with minimal slowdown (although, for some reason with 4.6.1 there's a big performance hit; works fine in 4.5.2). At worst case, there is actually have upwards of about 100,000 QGraphicsItems in the QGraphicsScene (not all being displayed) at any one time. When the scene reaches such high numbers then I do start seeing significant slow down.

    To manage the performance, I try to make sure only that only the items that actually need to be displayed are shown and I try to limit the instantiation of the QGraphicsItems to be only as needed.

    Also, take a look at the 40,000 Chips demo that comes with the Qt install. For the most part, this demo works fine and there are 40,000 graphical items on the screen at worst case. So, if you have a few thousand lines you shouldn't have any problems with performance.

    Good Luck!

  6. #6
    Join Date
    Sep 2009
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Graphics View : too many lines

    It's actually 56740 lines :P. But there will be much more.. There are lots of polygons, texts and images in the screen as well (not 56k of course).
    The problem is probably not the lines but creating 56k graphicsItem. Unnecessary memory consumption too.
    Before noticing graphics view I started this project with QPainter, and I printed the same amount of lines with polyline, it was no problem at all.

  7. #7
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Graphics View : too many lines

    Can't you group those lines into bigger objects? And draw these objects using polyline, except when the user is editing an object? You would need to create the required QGraphicsLineItem's when beginning to edit and removing them when finished.

Similar Threads

  1. Graphics View and the Pixmap
    By spawn9997 in forum Qt Programming
    Replies: 2
    Last Post: 26th June 2009, 23:12
  2. Graphics View Queries
    By linuxdev in forum Qt Programming
    Replies: 13
    Last Post: 7th January 2009, 10:44
  3. Graphics View or Paint ?
    By igor in forum Qt Programming
    Replies: 4
    Last Post: 21st January 2007, 14:21
  4. which is better QCanvas or graphics view?
    By neomax in forum General Discussion
    Replies: 1
    Last Post: 23rd November 2006, 16:19
  5. How to add new lines in a table view
    By klaus1111 in forum Newbie
    Replies: 1
    Last Post: 17th August 2006, 12:45

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.