Multiply text rows in one cells with different styles in QTableWidget (or QTableView)
-
Hi Guys!
I would like to achive what is shown in the picture:
My plan to achive this a QTableWidget with two kind of cells (a custom widget with two QLabel and if that is just one text line cell with just a simple QLabel), because in this way it would be possible for the style of the two lines cells to differ from each other.
Btw i dont know it is working with the header as well... but this seems like a very bad idea because for many records it will be a lot of widgets.So my question is, what is a good solution for such a table?
Thank you for your answers!
-
@Kaguro said in Multiply text rows in one cells with different styles in QTableWidget (or QTableView):
So my question is, what is a good solution for such a table?
Use QStyledItemDelegate 🙂
-
if it's not so big and lengthy for you, could I have an example of this please?
is this a solution for the 2 rows 1 row cells, headers and the different styles? -
A QStyledItemDelegate is responsible to paint a content of a cell. Since you know the row/column of the item to paint during painting you can distinguish between the separate paintings. Or ose QAbstractItemView::setDelegateForColumn()
See also https://doc.qt.io/qt-6/qstyleditemdelegate.html#details for an example. -
@Christian-Ehrlicher
Okay I try it, thanks! -
@Christian-Ehrlicher
Hi again!
No matter how I tried to have two lines of text in one cell and with different styles (as in the picture), it doesn't want to succeed. :( -
So how does your QStyledItemDelegate::paint() function look like?