How to set non-selectable default text on QComboBox?

后端 未结 3 1374
没有蜡笔的小新
没有蜡笔的小新 2020-12-06 09:54

Using a regular QComboBox populated with items, if currentIndex is set to -1, the widget is empty. It would be very useful to instead

3条回答
  •  眼角桃花
    2020-12-06 10:13

    One way you can do something similar is to set a placeholder:

    comboBox->setPlaceholderText(QStringLiteral("--Select Country--"));
    comboBox->setCurrentIndex(-1);
    

    This way you have a default that cannot be selected.

提交回复
热议问题