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.
The following image depicts exactly what I want. Instead of having "One" next to the button that push down the list, I want "Header" printed (which is not an element of the list).
Important, the checkbox are mandatory (which is why I'm using QComboBox).
I tried the function model.setHorizontalHeaderItem()
but it does not work (see the code below).
Please, help me.
#include <QApplication>
#include <QComboBox>
#include <QStandardItemModel>
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 );
comboBox->show();
return app.exec();
}