Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting default value for QcomboBox as empty

Tags:

python

pyqt

I'm on python 2.7 using pyqt 4.10, I've created a QcomboBox

for items in item_all:
    self.comboBox.addItem(items)

the item_all list is working perfectly but I need it to start with the default value as Empty (note that item_all list is being called from a DB table so I can't have an empty value to use it)

like image 980
Ahmed Wagdi Avatar asked Mar 09 '26 13:03

Ahmed Wagdi


2 Answers

Another solution is self.comboBox.setCurrentIndex(-1). The QCombobox is blank when it is created without adding another item in the list.

Python 3.10 and PyQt6 6.5.1

like image 176
Apollo11Mission Avatar answered Mar 12 '26 04:03

Apollo11Mission


Added a space to the item_all list before fetching it from the DB

item_all= ['',]
for items in c.fetchall():
    item_all.append(items)
self.comboBox_2.clear()
self.comboBox_2.addItems(item_all)
like image 25
Ahmed Wagdi Avatar answered Mar 12 '26 04:03

Ahmed Wagdi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!