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. Draw cells of a board quickly

Draw cells of a board quickly

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 918 Views
  • 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.
  • tjktak1002T Offline
    tjktak1002T Offline
    tjktak1002
    wrote on last edited by tjktak1002
    #1

    Hello everyone, I am trying to make a small simulation project which I need to draw a board of around 6500 cells representing animals and update it to present their movements. Here is an example:
    alt image
    Right now, I am drawing each cell individually. Each cell is a QPushButton and all the cells are grouped in a grid layout.
    Each time I made an update, I need to redraw the whole grid layout again and it usually takes me 2-3 seconds which is not very effective in term of time. I would like to know are there ways which I can improve my speed?
    Thank you and have a good day!

    JonBJ 1 Reply Last reply
    0
    • tjktak1002T tjktak1002

      Hello everyone, I am trying to make a small simulation project which I need to draw a board of around 6500 cells representing animals and update it to present their movements. Here is an example:
      alt image
      Right now, I am drawing each cell individually. Each cell is a QPushButton and all the cells are grouped in a grid layout.
      Each time I made an update, I need to redraw the whole grid layout again and it usually takes me 2-3 seconds which is not very effective in term of time. I would like to know are there ways which I can improve my speed?
      Thank you and have a good day!

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @tjktak1002
      Depends what you are using now to draw, which you don't say.

      One possibility would be to build a complete bitmap image of the whole lot and then show it. Another possibility, if the data arrives cumulatively and you want to show would be to accumulate a bunch of new data updates before showing, e.g. on a timer. Many possibilities.

      1 Reply Last reply
      3
      • tjktak1002T Offline
        tjktak1002T Offline
        tjktak1002
        wrote on last edited by tjktak1002
        #3

        @JonB hello, i would like to know if I use QImage would it improve my drawing time.
        Right now I create each cell as a QPushButton and present all the cells in a gridlayout

        JonBJ 1 Reply Last reply
        0
        • tjktak1002T tjktak1002

          @JonB hello, i would like to know if I use QImage would it improve my drawing time.
          Right now I create each cell as a QPushButton and present all the cells in a gridlayout

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @tjktak1002 said in Draw cells of a board quickly:

          Right now I create each cell as a QPushButton and present all the cells in a gridlayout

          Are you serious? That would be 6500 QPushButtons to add and draw!

          it usually takes me 2-3 seconds

          I'm surprised it isn't longer!

          You cannot possibly be talking about interchanging drawing buttons versus using an image, they are like apples & pears,

          Forget asking about efficiency of drawing for the moment. What are you actually wanting to achieve? I thought it as some kind of drawing, why in the world would you want all the points to be buttons?

          I need to draw a board of around 6500 cells representing animals and update it to present their movements

          You will want to use QGraphicsScene.

          tjktak1002T JonBJ 2 Replies Last reply
          0
          • JonBJ JonB

            @tjktak1002 said in Draw cells of a board quickly:

            Right now I create each cell as a QPushButton and present all the cells in a gridlayout

            Are you serious? That would be 6500 QPushButtons to add and draw!

            it usually takes me 2-3 seconds

            I'm surprised it isn't longer!

            You cannot possibly be talking about interchanging drawing buttons versus using an image, they are like apples & pears,

            Forget asking about efficiency of drawing for the moment. What are you actually wanting to achieve? I thought it as some kind of drawing, why in the world would you want all the points to be buttons?

            I need to draw a board of around 6500 cells representing animals and update it to present their movements

            You will want to use QGraphicsScene.

            tjktak1002T Offline
            tjktak1002T Offline
            tjktak1002
            wrote on last edited by
            #5

            @JonB haha I knew all the buttons is too much.
            I'm super new to QT and I have absolutely no idea how to draw a board with 6500 cells. And using buttons and grid layout is kinda simpler for me.
            Right now I just need a way to display a board of 127x53 which can be updated and redrawn as fast as possible.

            JoeCFDJ JonBJ 2 Replies Last reply
            0
            • JonBJ JonB

              @tjktak1002 said in Draw cells of a board quickly:

              Right now I create each cell as a QPushButton and present all the cells in a gridlayout

              Are you serious? That would be 6500 QPushButtons to add and draw!

              it usually takes me 2-3 seconds

              I'm surprised it isn't longer!

              You cannot possibly be talking about interchanging drawing buttons versus using an image, they are like apples & pears,

              Forget asking about efficiency of drawing for the moment. What are you actually wanting to achieve? I thought it as some kind of drawing, why in the world would you want all the points to be buttons?

              I need to draw a board of around 6500 cells representing animals and update it to present their movements

              You will want to use QGraphicsScene.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @JonB said in Draw cells of a board quickly:

              You will want to use QGraphicsScene.

              1 Reply Last reply
              1
              • tjktak1002T tjktak1002

                @JonB haha I knew all the buttons is too much.
                I'm super new to QT and I have absolutely no idea how to draw a board with 6500 cells. And using buttons and grid layout is kinda simpler for me.
                Right now I just need a way to display a board of 127x53 which can be updated and redrawn as fast as possible.

                JoeCFDJ Offline
                JoeCFDJ Offline
                JoeCFD
                wrote on last edited by JoeCFD
                #7

                @tjktak1002 create a QImage and you can set color to each pixel. Then paint this image. If one pixel is not big enough for one cell, use 4 and so on.

                1 Reply Last reply
                2
                • tjktak1002T tjktak1002

                  @JonB haha I knew all the buttons is too much.
                  I'm super new to QT and I have absolutely no idea how to draw a board with 6500 cells. And using buttons and grid layout is kinda simpler for me.
                  Right now I just need a way to display a board of 127x53 which can be updated and redrawn as fast as possible.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #8

                  @tjktak1002
                  If you want to be able to interact with or address the items [animals :) ] then certainly graphics items.
                  If you just want to recalculate a bitmap like your picture shows and produce a complete new "board" in one go as fast as possible then produce a non-interactive image like @JoeCFD suggests.

                  tjktak1002T 1 Reply Last reply
                  2
                  • JonBJ JonB

                    @tjktak1002
                    If you want to be able to interact with or address the items [animals :) ] then certainly graphics items.
                    If you just want to recalculate a bitmap like your picture shows and produce a complete new "board" in one go as fast as possible then produce a non-interactive image like @JoeCFD suggests.

                    tjktak1002T Offline
                    tjktak1002T Offline
                    tjktak1002
                    wrote on last edited by
                    #9

                    @JonB @JoeCFD Hello again, I update from using QPushButton to using QImage. Now, it only took me around 0,2 seconds for each update.
                    Thank you very much for your help. :D

                    1 Reply Last reply
                    1

                    • Login

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