[SOLVED] QTableview with expandable rows
-
wrote on 28 Feb 2012, 13:45 last edited by
Hi, I need to have rows with expandable icon (+) and child rows which have dedicated headers like below:
@Column1 Column2 Column3 -Row1 Child Column1 Child Column2 Child Column3 --------------- --------------- -------------- Child Row1 Child Row 2 Child Row3 ------------- ------------------ -------------- +Row2 @ Any help would be appreciated!
-
wrote on 28 Feb 2012, 14:06 last edited by
did you look at "QTreeView":http://developer.qt.nokia.com/doc/qt-4.8/qtreeview.html
-
wrote on 28 Feb 2012, 14:11 last edited by
does QTreeView able to have dedicated columns for child rows?
-
wrote on 28 Feb 2012, 21:02 last edited by
Use QTreeView with a QTableModel; if you need more control, I'll suggest to design a custom delegate , maybe a simple composite widget like kget's:
!http://s1.picofile.com/file/7315852361/snapshot16.jpeg(kget)! -
wrote on 29 Feb 2012, 06:43 last edited by
Also interesting perhaps is "QTitanDataGrid":http://devmachines.com/products/qtitandatagrid-overview.html
-
wrote on 13 Mar 2012, 06:36 last edited by
I've found the solution. It's so easy and simple. We may do that using QTreeWidget.
@
// Row 1
QTreeWidgetItem *row1 = new QTreeWidgetItem(ui->treeWidget);
row1->setText(0, "Row 1"); //Column 1
row1->setText(1, "Data"); //Column 2// Row 2 QTreeWidgetItem *row2 = new QTreeWidgetItem(ui->treeWidget); row2->setText(0, "Row 2"); //Column 1 //Child row for Row1 QTreeWidgetItem *row1_child = new QTreeWidgetItem(row1); //Custom widget for child row QPushButton *pb = new QPushButton("Custom Child", ui->treeWidget ); //Set custom widget to the child row ui->treeWidget->setItemWidget(row1_child, 0, pb); row1_child->setFirstColumnSpanned(true);
@