PDA

View Full Version : Add separator to QComboBox using QStringList entries



mrknight
25th November 2010, 05:57
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

ngenen
25th November 2010, 06:19
Well, just use QComboBox::insertSeparator(int index) that would insert a separator, in your example the index would be 5, so

ui->comboBox->insertSeparator(5);
that would make all the job :)

mrknight
26th November 2010, 23:29
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.

ngenen
26th November 2010, 23:31
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!