How to paint a table from an item delegate?
I have a table where I display mostly text, however in some cases some cells have a list of values.
I wanted to render those lists as a one column table within the cell. For that reason I made my own item delegate and overloaded the QitemDelegate : : paint() function.
Inside, if I do not detect a list I just pass the flow :
However, if I have a list I want to build that table. For testing I have:
Code:
tableWidget->setRowCount(4);
tableWidget->setColumnCount(1);
Now my idea was to use that QTableWidget to paint the table, an so far the only way I saw to pass a QPainter parameter was with the render function:
Code:
tableWidget->render(painter);
That does not work and the cell looks empty (with/within saving/restoring the state before using render() ). Any idea about how could I reuse the painter of QTableWidget to draw that table???
Re: How to paint a table from an item delegate?
Why don't you just draw the items directly?
Re: How to paint a table from an item delegate?
I want to have have the list separated by lines, later I might need to add a second column. I did not like the idea of reimplementing the table widget/view painter... plus, I would like to learn how to reuse the painter of other widgets
Re: How to paint a table from an item delegate?
Quote:
Originally Posted by
frank100
I did not like the idea of reimplementing the table widget/view painter...
Creating a new widget every time some other widget is painted is a very bad idea.
Quote:
plus, I would like to learn how to reuse the painter of other widgets
When painting yourself, you'd be doing the exact same thing when it comes to "reusing the painter of another widget".
Re: How to paint a table from an item delegate?
Thanks for the help, I realize I did not make a clear question :-(
Quote:
Originally Posted by
wysota
Creating a new widget every time some other widget is painted is a very bad idea.
That was not my intention. Although I do that in my example, actually I defined one static QTableWidget instance inside the constructor of my item delegate. I rewrote that part within the paint() function of the question to make it less cluttered with code.
Quote:
Originally Posted by
wysota
When painting yourself, you'd be doing the exact same thing when it comes to "reusing the painter of another widget".
That is what I want. For drawing a table within a cell I must align the text and draw lines for the grid. I expected that if the QTableView/QTableWidget have a painter doing what I want, there should be a way to reuse it.
Somehow I suppose I can give them the QPainter I receive from one of the parameters and let them do the drawing for me.
I could also make the question more generic. I have a table with a custom item delegate and I want this delegate to draw tables within some of the cells. I thought that painting myself was the way to go :confused:
Re: How to paint a table from an item delegate?
Quote:
Originally Posted by
frank100
That was not my intention. Although I do that in my example, actually I defined one static QTableWidget instance inside the constructor of my item delegate. I rewrote that part within the paint() function of the question to make it less cluttered with code.
But you still have to repopulate the widget each time you paint a cell.
Quote:
That is what I want. For drawing a table within a cell I must align the text and draw lines for the grid. I expected that if the QTableView/QTableWidget have a painter doing what I want, there should be a way to reuse it.
I think you misinterpret what "painter" is.