Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to speed up when I need to draw huge number of objects in a view?
Forum Updated to NodeBB v4.3 + New Features

how to speed up when I need to draw huge number of objects in a view?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 601 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vigi
    wrote on last edited by
    #1

    how to speed up when I need to draw huge number of objects in a view?
    currently, I use QGraphicsView and put the objects into a QGraphicSneces ,however when the object number hits 50000000 , it takes lot of time.
    ///below shows my code:

    int main(int argc, char *argv[])
    {

    QApplication app(argc, argv);
    QMainWindow window;
    
    window.show();
    
    QGraphicsScene* scene = new QGraphicsScene();
    int count = 3000;
    int step = 10;
    for (int i=0; i<count; i++){
        for (int j=0; j<count; j++) {
            int rand_x = step*i;
            int rand_y = step*j;
            QGraphicsRectItem* rect = new QGraphicsRectItem();
            rect->setRect(rand_x,rand_y,100,100);
            scene->addItem(rect);
        }
    }
    
    
    
    QGraphicsView * view = new QGraphicsView(scene);
    //view->setScene(scene);
    //view->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
    view->show();
    window.setCentralWidget(view);
    
    return app.exec();
    

    }

    JKSHJ 1 Reply Last reply
    0
    • V vigi

      how to speed up when I need to draw huge number of objects in a view?
      currently, I use QGraphicsView and put the objects into a QGraphicSneces ,however when the object number hits 50000000 , it takes lot of time.
      ///below shows my code:

      int main(int argc, char *argv[])
      {

      QApplication app(argc, argv);
      QMainWindow window;
      
      window.show();
      
      QGraphicsScene* scene = new QGraphicsScene();
      int count = 3000;
      int step = 10;
      for (int i=0; i<count; i++){
          for (int j=0; j<count; j++) {
              int rand_x = step*i;
              int rand_y = step*j;
              QGraphicsRectItem* rect = new QGraphicsRectItem();
              rect->setRect(rand_x,rand_y,100,100);
              scene->addItem(rect);
          }
      }
      
      
      
      QGraphicsView * view = new QGraphicsView(scene);
      //view->setScene(scene);
      //view->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
      view->show();
      window.setCentralWidget(view);
      
      return app.exec();
      

      }

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      @vigi said in how to speed up when I need to draw huge number of objects in a view?:

      when the object number hits 50000000 , it takes lot of time.

      50 million is a lot! Your computer will probably run out of resources.

      A 1080p screen only has 2 million pixels and a 4K screen only has 8 million pixels, so you can't possibly display 50 million rectangles on the screen.

      how to speed up when I need to draw huge number of objects in a view?

      Don't draw all 50 million at the same time. Only draw the objects that are inside (and near) your viewport. When the user pans around, draw new objects and delete old ones.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      7
      • V Offline
        V Offline
        vigi
        wrote on last edited by
        #3

        can you show me an example?

        JKSHJ A 2 Replies Last reply
        0
        • V vigi

          can you show me an example?

          JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          @vigi said in how to speed up when I need to draw huge number of objects in a view?:

          can you show me an example?

          Can you try it yourself first?

          Why do you need so many objects, anyway?

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0
          • V vigi

            can you show me an example?

            A Offline
            A Offline
            Asperamanca
            wrote on last edited by
            #5

            @vigi Look at the 40000 chips example. It basically does what you want. But I have serious doubts that you can make it work efficiently with 50 million objects.
            What is your actual use case?

            1 Reply Last reply
            3

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved