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. Insert fill circle into cell of QTableWidget
Forum Updated to NodeBB v4.3 + New Features

Insert fill circle into cell of QTableWidget

Scheduled Pinned Locked Moved Solved General and Desktop
88 Posts 5 Posters 47.6k 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.
  • mrjjM mrjj

    @juaniyoalm
    Hi
    Well the delegate cannot go read into other external classes.
    So you have to at some point take the values from the classes and
    put into the model.
    How often does those values change in the classes ?

    J Offline
    J Offline
    juaniyoalm
    wrote on last edited by
    #23

    @mrjj

    The parameters will change very often. There will be hundreds of instances of the class and the values ​​will change.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #24

      The problem is not in the number of instances but rather how you access them.

      How are you currently handling these differed classes ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • J Offline
        J Offline
        juaniyoalm
        wrote on last edited by
        #25

        @mrjj @SGaist Hi!!

        The program will be a simulation of the habitat of fungus and fungivores. I have a world class, which contains a matrix (world), and an array of fungivores. The matrix is composed of cell. The cell class contains an array of fungivores (fungivores that are in that cell) and an int that represents the amount of fungus there is. In the course of the execution the value of fungus and the number of fungivores that there will be in each cell will change. That's what I have to represent in the UI. The amount of fungus will represent it by painting the green cells, with an intensity between 0 and 255, depending on the value, and the amount of fungivors will represent it with a circle, the size of the circle will depend on the value. Once I have this sequential version, I will have to make a parallel version.

        JonBJ 1 Reply Last reply
        0
        • J juaniyoalm

          @mrjj @SGaist Hi!!

          The program will be a simulation of the habitat of fungus and fungivores. I have a world class, which contains a matrix (world), and an array of fungivores. The matrix is composed of cell. The cell class contains an array of fungivores (fungivores that are in that cell) and an int that represents the amount of fungus there is. In the course of the execution the value of fungus and the number of fungivores that there will be in each cell will change. That's what I have to represent in the UI. The amount of fungus will represent it by painting the green cells, with an intensity between 0 and 255, depending on the value, and the amount of fungivors will represent it with a circle, the size of the circle will depend on the value. Once I have this sequential version, I will have to make a parallel version.

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by JonB
          #26

          @juaniyoalm
          So can you keep those fungus-intensity-ints in (a column in) your model? Then your view can access it.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #27

            Is the matrix a two dimensional table ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            J 1 Reply Last reply
            0
            • SGaistS SGaist

              Is the matrix a two dimensional table ?

              J Offline
              J Offline
              juaniyoalm
              wrote on last edited by juaniyoalm
              #28

              @SGaist
              Yes, in each cell there is fungus (int value) and fungivores (array of fungivores).

              I've tried pass QPair or Qlist to QStandarItemModel but is not posible cast to qvariant

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #29

                What are you currently using to store that "matrix" ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                1
                • J Offline
                  J Offline
                  juaniyoalm
                  wrote on last edited by
                  #30

                  Vector<Vector<Cell>>

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    juaniyoalm
                    wrote on last edited by
                    #31

                    Some answer please???

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #32

                      Please show some patience and allow 24 hours to run before bumping your own thread. This is a community forum where people answer on their own time. They might not even live in the same timezone as you.

                      As for your current trouble. You can build a QAbstractTableModel that will give access to your matrix. For the specific members of your Cell class, you can use custom roles.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      J 1 Reply Last reply
                      2
                      • SGaistS SGaist

                        Please show some patience and allow 24 hours to run before bumping your own thread. This is a community forum where people answer on their own time. They might not even live in the same timezone as you.

                        As for your current trouble. You can build a QAbstractTableModel that will give access to your matrix. For the specific members of your Cell class, you can use custom roles.

                        J Offline
                        J Offline
                        juaniyoalm
                        wrote on last edited by
                        #33

                        @SGaist

                        I'm sorry, it was my vacation day and I wanted to move forward with the project. I'm sorry.

                        To assign the matrix to the model simply the model creates a variable of the same type as the matrix and initialize the model I assign it in some way, is it correct? I do not understand the roles very well ...

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #34

                          You should also provide APIs that will allow you ton modify that matrix.

                          As for the roles, they are there to retrieve specific information from the model's elements.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          2
                          • J Offline
                            J Offline
                            juaniyoalm
                            wrote on last edited by juaniyoalm
                            #35

                            @SGaist said in Insert fill circle into cell of QTableWidget:

                            You should also provide APIs that will allow you ton modify that matrix.
                            As for the roles, they are there to retrieve specific information from the model's elements.

                            I'm sorry but I still do not understand well the models and roles in QT.
                            Can anyone give me an example of how the model class should be?

                            I have a matrix (vector <vector <Cell >>) and when modifying some attributes of the Cell class, have to change what is painted in the graphic representation (Only the one in the cell corresponding to the coordinates of the matrix).

                            mrjjM 1 Reply Last reply
                            0
                            • J juaniyoalm

                              @SGaist said in Insert fill circle into cell of QTableWidget:

                              You should also provide APIs that will allow you ton modify that matrix.
                              As for the roles, they are there to retrieve specific information from the model's elements.

                              I'm sorry but I still do not understand well the models and roles in QT.
                              Can anyone give me an example of how the model class should be?

                              I have a matrix (vector <vector <Cell >>) and when modifying some attributes of the Cell class, have to change what is painted in the graphic representation (Only the one in the cell corresponding to the coordinates of the matrix).

                              mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by
                              #36

                              @juaniyoalm
                              Hi
                              Its something like this
                              https://meetingcpp.com/blog/items/an-introduction-into-qt-part-3.html
                              However he uses a
                              std::vector<PersonalData> mydata;
                              where you have
                              vector <vector <Cell >>
                              so you need to use both index.row and index.col
                              to address your matrix. ( the data)

                              J 1 Reply Last reply
                              2
                              • mrjjM mrjj

                                @juaniyoalm
                                Hi
                                Its something like this
                                https://meetingcpp.com/blog/items/an-introduction-into-qt-part-3.html
                                However he uses a
                                std::vector<PersonalData> mydata;
                                where you have
                                vector <vector <Cell >>
                                so you need to use both index.row and index.col
                                to address your matrix. ( the data)

                                J Offline
                                J Offline
                                juaniyoalm
                                wrote on last edited by
                                #37

                                @mrjj Thanks so much.

                                I was doing it that way, but how did I assign the matrix to the model variable? At this moment, I am creating the matrix in mainwindow class ...

                                mrjjM 1 Reply Last reply
                                0
                                • J juaniyoalm

                                  @mrjj Thanks so much.

                                  I was doing it that way, but how did I assign the matrix to the model variable? At this moment, I am creating the matrix in mainwindow class ...

                                  mrjjM Offline
                                  mrjjM Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on last edited by mrjj
                                  #38

                                  @juaniyoalm
                                  Hi
                                  well the vector <vector <Cell >> matrix could be inside the model
                                  and you would use method like the Addperson in sample to fill it.
                                  Much like you do now. when maxtrix is outside of the model.
                                  You could also fill it in mainwindow and simply give whole matrix to model
                                  to copy it to internal variable.(matrix) but thats a bit waste full.

                                  Also i been wanting to ask you. You do use a TableView because you need scrolling correct?
                                  I mean there are far more rows with cells than can fit on on screen ?

                                  J 1 Reply Last reply
                                  3
                                  • mrjjM mrjj

                                    @juaniyoalm
                                    Hi
                                    well the vector <vector <Cell >> matrix could be inside the model
                                    and you would use method like the Addperson in sample to fill it.
                                    Much like you do now. when maxtrix is outside of the model.
                                    You could also fill it in mainwindow and simply give whole matrix to model
                                    to copy it to internal variable.(matrix) but thats a bit waste full.

                                    Also i been wanting to ask you. You do use a TableView because you need scrolling correct?
                                    I mean there are far more rows with cells than can fit on on screen ?

                                    J Offline
                                    J Offline
                                    juaniyoalm
                                    wrote on last edited by
                                    #39

                                    @mrjj

                                    Yes, there is no row limit, it can be 20 rows, 100 or 1000 xD. I always have to think about what I do to behave well when I do the parallel implementation, using pthread and openmp.

                                    mrjjM 1 Reply Last reply
                                    0
                                    • J juaniyoalm

                                      @mrjj

                                      Yes, there is no row limit, it can be 20 rows, 100 or 1000 xD. I always have to think about what I do to behave well when I do the parallel implementation, using pthread and openmp.

                                      mrjjM Offline
                                      mrjjM Offline
                                      mrjj
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #40

                                      @juaniyoalm
                                      Ok so scrolling is needed:)
                                      Also make sure to check out QtConcurrent and QThread before jumping to pthread.

                                      J 1 Reply Last reply
                                      0
                                      • mrjjM mrjj

                                        @juaniyoalm
                                        Ok so scrolling is needed:)
                                        Also make sure to check out QtConcurrent and QThread before jumping to pthread.

                                        J Offline
                                        J Offline
                                        juaniyoalm
                                        wrote on last edited by juaniyoalm
                                        #41

                                        @mrjj

                                        ok, I will look it.

                                        I have a doubt, when I modify a value of the Cell class (this is done in a method of the Cell class ), it will be modified automatically in the model or I have to do model-> setData (model-> index (i, j) , matrix [i] [j] -> getModifiedValue ())? The Cell of matrix are pointer...

                                        mrjjM 1 Reply Last reply
                                        0
                                        • J juaniyoalm

                                          @mrjj

                                          ok, I will look it.

                                          I have a doubt, when I modify a value of the Cell class (this is done in a method of the Cell class ), it will be modified automatically in the model or I have to do model-> setData (model-> index (i, j) , matrix [i] [j] -> getModifiedValue ())? The Cell of matrix are pointer...

                                          mrjjM Offline
                                          mrjjM Offline
                                          mrjj
                                          Lifetime Qt Champion
                                          wrote on last edited by
                                          #42

                                          @juaniyoalm
                                          Well if you go with QAbstractTableModel
                                          your matrix IS the data so if you modify it
                                          and call dataChanged (model call ) to let view know data has been altered.

                                          J 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