Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QComboBox and HeaderItem
jp_doyon1 last edited by
Dear all, I have a QComboBox with a QStandardItemModel, which contains a single item named "One".
I want the QComboBox to have an header (I'm not sure this is the correct technical term ...) which will always be the same.
 To be more precise, running the code below leads to the following output:
"One" (as the header) + "One" (with a checkbox).
 What I'm looking for is as follows:
"Header" (as the header) + "One" (with a checkbox).
I tried the function "model.setHorizontalHeaderItem()" but it leads to the same as  above.
Please, help me.
int main( int argc, char **argv )
QApplication app( argc, argv );
QComboBox* comboBox = new QComboBox();
QStandardItemModel model( 1, 1 );
QStandardItem *item = new QStandardItem( QString("One") );
item->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
item->setData ( Qt::Unchecked, Qt::CheckStateRole );
model.setItem(0, 0, item);
model.setHorizontalHeaderItem( 0, new QStandardItem( "Header" ) );
comboBox->setModel( &model );
zeljko last edited by
See QComboBox::setView , QComboBox uses QListWidget as view by default and there's no header. Set QTreeWidget as QComboBox view and there you can set header.