Python - 如何保持QComboBox的QLineEdit不添加新项目

时间:2017-09-02 20:26:21

标签: python pyqt

每当您向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, 

0 个答案:

没有答案