Add separator to QComboBox using QStringList entries
What character, if any, is used to denote 'a separator goes here' when populating a QComboBox using QStringList entries. Most other GUI engines will replace a single underbar "_" or dash "-" with a separator.
I want to use a separated list within a QInputDialog (see below), but can find no documentation referring to how this would be done (other than doing it long hand).
// populate items with units of measure
items << tr("Kilometres") << tr("Metres") << tr("Decimetres") << tr("Centimetres") << tr("Millimetres") << tr("-") << tr("Miles") << tr("Yards") << tr("Feet") << tr("Inches");
QString item = QInputDialog::getItem(this, tr(""), tr("Unit of measure:"), items, 0, false, &ok);
If this doesn't exist, it would make sense to add it for the next version.
Micheal
Re: Add separator to QComboBox using QStringList entries
Well, just use QComboBox::insertSeparator(int index) that would insert a separator, in your example the index would be 5, so
Code:
ui->comboBox->insertSeparator(5);
that would make all the job :)
Re: Add separator to QComboBox using QStringList entries
Normally, I would. But the QInputDialog::getItem() builds the combo box directly from the QStringList. I believe this is an oversight that needs to be addressed, rather than something I am missing.
Re: Add separator to QComboBox using QStringList entries
You can insert the separator after creating the combo, you will need calculate where do you want to insert it and calculate the index. just that!