how can i make QComboBox
allow search but preventing user from adding new item my code :
self.products = QtWidgets.QComboBox(self.conts[self.ind])
self.products.setEditable(True)
self.products.resize(190, 30)
self.products.move(400, 20)
self.products.setStyleSheet('background:#2c3e50')
self.products.show()
self.products.setEditable(True)
is not what i need because user can type any thing
How to prevent user from adding new item , just search for currently setted items
As you point out you have to enable the editable
property and set the insertPolicy
property to QComboBox::NoInsert
:
import sys
from PyQt5 import QtWidgets
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
w = QtWidgets.QComboBox()
w.addItems(["One", "Two", "Three", "Four", "Five"])
w.show()
sys.exit(app.exec_())
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.