Insert fill circle into cell of QTableWidget
-
Thank you, the solution is good for me!!! but I would like that the background of cells is fill too. This colour have to change too.
I thought about inserting a rectangle but I would need the circle to be located on top...@juaniyoalm
Hi
Just use other paint methods like
painter->drawRect(opt.rect); -
@juaniyoalm
Hi
Just use other paint methods like
painter->drawRect(opt.rect);@mrjj Thank you so much!!
Okay, I have that solved.
Another question is that the size of each circle depends on a value that my mushroom class has. In my class I created a paint method but I do not know how to link that method with the delegate or what is the way to write the method.
-
@mrjj Thank you so much!!
Okay, I have that solved.
Another question is that the size of each circle depends on a value that my mushroom class has. In my class I created a paint method but I do not know how to link that method with the delegate or what is the way to write the method.
@juaniyoalm
Hi, is the value in the model ?
The delegate can use values from model.
so the color and size of circle could come from model. -
@juaniyoalm
Hi, is the value in the model ?
The delegate can use values from model.
so the color and size of circle could come from model.No, that value is in a c++class. I have to create a custom model... It's ok?? Or I can use a default model??
-
No, that value is in a c++class. I have to create a custom model... It's ok?? Or I can use a default model??
@juaniyoalm
You can use http://doc.qt.io/qt-5/qstandarditemmodel.html
if it is. dont have to be custom.
I though you already had a model ?
Also is this with a QTableWidget ?
(it uses a model already ) -
@juaniyoalm
You can use http://doc.qt.io/qt-5/qstandarditemmodel.html
if it is. dont have to be custom.
I though you already had a model ?
Also is this with a QTableWidget ?
(it uses a model already ) -
@juaniyoalm
Super. With view its much easier.
so you have to construct a model with the data
that comes from the class.
Did you make a qstandarditemmodel before ? -
@juaniyoalm
Super. With view its much easier.
so you have to construct a model with the data
that comes from the class.
Did you make a qstandarditemmodel before ?@mrjj
Yes, I did but without data class -
@mrjj
Do you show me how to make?? -
@mrjj
Do you show me how to make??@juaniyoalm
Hi
Please read about userRoles and setDatahttp://doc.qt.io/qt-5/model-view-programming.html
section Item rolesyou can simply put the color / size in user role, or you can have
it directly as an item in your model.
Both ways are fine.
Then delegate read the user role and use the data. -
I read it and I have tried it but my problem is that size circle depends that value of class and colour of background another value of class. I don't know how do it...
-
I read it and I have tried it but my problem is that size circle depends that value of class and colour of background another value of class. I don't know how do it...
@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 ? -
@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 ?The parameters will change very often. There will be hundreds of instances of the class and the values will change.
-
The problem is not in the number of instances but rather how you access them.
How are you currently handling these differed classes ?
-
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.
-
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.
@juaniyoalm
So can you keep those fungus-intensity-ints in (a column in) your model? Then your view can access it. -
Is the matrix a two dimensional table ?
-
@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
-
What are you currently using to store that "matrix" ?
-
Vector<Vector<Cell>>