每当您向QLineEdit
添加基本QComboBox
时,如果您在QComboBox
中输入任何内容并按[Enter],QLineEdit
文字就会添加到QComboBox
QComboBox
。
为了清楚起见,我仍然希望能够像平常一样管理QLineEdit
项目(添加,删除等)。在这种情况下,只允许import functools
import sys
# Use PySide/PyQt. Doesn't matter
from Qt import QtWidgets
def print_items(combo_box):
print([combo_box.itemText(index) for index in range(combo_box.count())])
def main():
app = QtWidgets.QApplication([])
window = QtWidgets.QComboBox()
line_edit = QtWidgets.QLineEdit()
line_edit.editingFinished.connect(functools.partial(print_items, window))
window.setLineEdit(line_edit)
window.show()
sys.exit(app.exec_())
# start writing in the QLineEdit and press [Enter].
# The item is now in the QComboBox and print in the terminal
if __name__ == '__main__':
main()
添加新项目。
我非常喜欢一个不需要子类化内置QLineEdit / QComboBox的解决方案
有谁知道怎么做?
mode = 'text', text = ~Count,