Search code examples
c++qtqwidgetqtablewidget

QTableWidget : personal widget as header?


What is the easiest way (without subclassing QTableWidget if possible) to put a personnal Widget (which is a group of QPixmap + QLabel + QComboBox in my case) as headers in a QTableWidget ?

It is relatively easy to do it for the array content as we have the function QTableWidget::setCellWidget(int row, int column, QWidget * widget), but for the headers, we only have QTableWidget::setHorizontalHeaderItem (int column, QTableWidgetItem * item)

Thank you very much !

EDIT : Maybe I've found a very unelegant way to do this that may work :

1) I initialize each column with an empty QString header

2) I extract the size and position of each section of the header with _table->horizontalHeader()->sectionPosition(index) and _table->horizontalHeader()->sectionSize(index)

3) Then I draw a QFrame onto each section with a little margin

4) And finally, I load my QWidgets in these QFrame

If any one else has a better solution, I'm interested...


Solution

  • I guess setCellWidget() will do the job. I don't see an easier way. Instead of a QFrame you might also use a QWidget, if you don't use the additional functionality of QFrame.