Important: Please read the Qt Code of Conduct -

Drawing 70k objects in QGraphicsView - lag lag lag

  • Hey

    I'm trying to draw quite..." few" lines/reacts inside QGraphicsView I've configured

        QOpenGLWidget *mGlWidget = new QOpenGLWidget();//QGLFormat(QGL::SampleBuffers));
        QSurfaceFormat format;
        format.setVersion(4, 5);

    And went on with painting but as far as I can tell its very "slow task". Is there anything else I can do or I have to go full standalone opengl solution? I have disabled paiting (void paint(){return;}) and it was pretty slow then too so mhmhm.... ? Perhaps I can't have a lot of items in QGraphicsView?


  • It's probably less to do with whether it is a full openGL app, and more to do with the methods you're using to generate your scene. 70k objects? OK...nothing about rendering hardware or whether you are optimizing your scene generation?

  • @Kent-Dorfman Hey, hardware wise 2990wx/2080super. As to generation, its just a loop for int x=0;x<100000;++x{}, I'm not even drawing the items. Just added to scene one time and then panning around in scene.

    Its my attempt at uv editor :- ) So object count can go well over 1 mil + and so on.

  • @Dariusz
    GraphicsView is single threaded and not hardware accelerated. That said, it's relatively efficient code, so adding 70k items might take a bit of time, but it should be doable.

    I don't see any code what kind of items you are trying to add. The problem might lie there.

    The code you posted has little to do with GraphicsView per se, so the question is a bit unclear to me.

  • @Asperamanca Hey, The code I added is being executed in graphicsView, it configures it to use openGL for drawing instead of CPU.

    The problem is not how long it takes to add items, but how well it performs once I added them. I'm using a base QGraphicsItem as my class and then extended that. In my extension I have disabled drawing so there is 0 drawing happening. Only items added to scene and qt run its own tests on them. As far as I can tell the drawing is not the issue, but just processing 70k items.

    I'm looking in to building openGL app for this as it does not look like QGraphicsView is optimized for it.


  • @Dariusz
    If you don't use any GraphicsView features, you probably should not use GraphicsView at all. Consider an alternative like Qt3d or QtQuick3

  • @Asperamanca said in Drawing 70k objects in QGraphicsView - lag lag lag:

    If you don't use any GraphicsView features, you probably should not use GraphicsView at all. Consider an alternative like Qt3d or QtQuick3

    Well I'm just trying to understand where the bottleneck is... I did drawing, I had 1 fps. So I disabled all paint functions to see if that help, that did help, but I'm still having issues... so I take graphicsView is not for very large scenes then ?

  • Lifetime Qt Champion

    I if take the 40000 sample
    and double the items so it creates 80.000, its still not lagging.

  • @mrjj Hey hmmm, I just tried that example, paning/moving seems to somewhat work, but selecting/moving and bigger action begin to lag mhmhmhmm. Darn I was really hopping to do it in qt.

  • Why would QGraphicsView go out of its way to slow down the OpenGL implementation? Are you using modern OpengGL techniques or the old interface which is slow and outdated? Are you using shaders? If no, then it probably isn't modern OpenGL. Without showing your code you are not helping yourself sort this out.
    This book helped me. It is based on post 3.3 opengl if I remember right.

    Edit: Also, yes, it is possible Qt is not what you need, but I don't think Qt is inherently slow at OpenGL.

  • @Dariusz your expression "mhmhmhmm" made me think of this all day:

  • Lifetime Qt Champion

    Ok so you could get the 40K sample to lag also ?

Log in to reply