3

If I do:

QComboBox *cb = ...; 

cb->clear();
cb->addItem(...);
cb->insertSeparator(1);
cb->addItem(...);

Is cb->count() going to return 2 or 3?

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Claudiu
  • 224,032
  • 165
  • 485
  • 680

2 Answers2

3

The separators count. The count() will be equal to 3.

#include <QtWidgets>

int main(int argc, char *argv[])
{
   QApplication a(argc, argv);
   QComboBox cb;
   cb.addItem("Foo");
   cb.insertSeparator(1);
   cb.addItem("Bar");
   Q_ASSERT(cb.count() == 3);
   return 0;
}
Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
3

QComboBox::AddItem is a shortcut to insert an item in the last position; the default insert method is QComboBox::InsertItem which is invoked by AddItem and increment the items count; QComboBox::InsertSeparator invokes InsertItem so, yes, a separator count as an item

gengisdave
  • 1,969
  • 5
  • 21
  • 22