I've added a combo box to the header of a QTableWidget. I assume it works similar with a QTableView. Here's an outline of what I've done:
- Create a new class MyHeaderView derived from QHeaderView
- In the CTOR of MyHeaderView, I create a new QComboBox with the header view viewport as parent:
new QComboBox(viewport())
- In the CTOR, connect QHeaderView signal sectionResized(int,int,int) to a slot onSectionResized(int,int,int) of the new class
MyHeaderView. This slot is responsible for moving my combo box to the right place and resize it in case that the section
size changes.
- Implement onSectionResized(int section, int oldSize, int newSize) in class MyHeaderView. In my implementation, I use
QSize s = sectionSizeFromContents(section) to get width and height.
For moving the combo box, I use sectionViewportPosition(section) to determine the section start position.
Hope this will help you a little bit.
Bookmarks