本文整理汇总了Python中spyderlib.qt.QtGui.QComboBox.addItem方法的典型用法代码示例。如果您正苦于以下问题:Python QComboBox.addItem方法的具体用法?Python QComboBox.addItem怎么用?Python QComboBox.addItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spyderlib.qt.QtGui.QComboBox
的用法示例。
在下文中一共展示了QComboBox.addItem方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FormComboWidget
# 需要导入模块: from spyderlib.qt.QtGui import QComboBox [as 别名]
# 或者: from spyderlib.qt.QtGui.QComboBox import addItem [as 别名]
class FormComboWidget(QWidget):
update_buttons = Signal()
def __init__(self, datalist, comment="", parent=None):
QWidget.__init__(self, parent)
layout = QVBoxLayout()
self.setLayout(layout)
self.combobox = QComboBox()
layout.addWidget(self.combobox)
self.stackwidget = QStackedWidget(self)
layout.addWidget(self.stackwidget)
self.combobox.currentIndexChanged.connect(
self.stackwidget.setCurrentIndex)
self.widgetlist = []
for data, title, comment in datalist:
self.combobox.addItem(title)
widget = FormWidget(data, comment=comment, parent=self)
self.stackwidget.addWidget(widget)
self.widgetlist.append(widget)
def setup(self):
for widget in self.widgetlist:
widget.setup()
def get(self):
return [ widget.get() for widget in self.widgetlist]
示例2: RunConfigDialog
# 需要导入模块: from spyderlib.qt.QtGui import QComboBox [as 别名]
# 或者: from spyderlib.qt.QtGui.QComboBox import addItem [as 别名]
class RunConfigDialog(BaseRunConfigDialog):
"""Run configuration dialog box: multiple file version"""
def __init__(self, parent=None):
BaseRunConfigDialog.__init__(self, parent)
self.file_to_run = None
self.combo = None
self.stack = None
def run_btn_clicked(self):
"""Run button was just clicked"""
self.file_to_run = to_text_string(self.combo.currentText())
def setup(self, fname):
"""Setup Run Configuration dialog with filename *fname*"""
combo_label = QLabel(_("Select a run configuration:"))
self.combo = QComboBox()
self.combo.setMaxVisibleItems(20)
self.combo.setSizeAdjustPolicy(QComboBox.AdjustToMinimumContentsLength)
self.combo.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
self.stack = QStackedWidget()
configurations = _get_run_configurations()
for index, (filename, options) in enumerate(configurations):
if fname == filename:
break
else:
# There is no run configuration for script *fname*:
# creating a temporary configuration that will be kept only if
# dialog changes are accepted by the user
configurations.insert(0, (fname, RunConfiguration(fname).get()))
index = 0
for filename, options in configurations:
widget = RunConfigOptions(self)
widget.set(options)
self.combo.addItem(filename)
self.stack.addWidget(widget)
self.connect(self.combo, SIGNAL("currentIndexChanged(int)"),
self.stack.setCurrentIndex)
self.combo.setCurrentIndex(index)
self.add_widgets(combo_label, self.combo, 10, self.stack)
self.add_button_box(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
self.setWindowTitle(_("Run Settings"))
def accept(self):
"""Reimplement Qt method"""
configurations = []
for index in range(self.stack.count()):
filename = to_text_string(self.combo.itemText(index))
runconfigoptions = self.stack.widget(index)
if index == self.stack.currentIndex() and\
not runconfigoptions.is_valid():
return
options = runconfigoptions.get()
configurations.append( (filename, options) )
_set_run_configurations(configurations)
QDialog.accept(self)
示例3: create_combobox
# 需要导入模块: from spyderlib.qt.QtGui import QComboBox [as 别名]
# 或者: from spyderlib.qt.QtGui.QComboBox import addItem [as 别名]
def create_combobox(self, text, choices, option, default=NoDefault,
tip=None):
"""choices: couples (name, key)"""
label = QLabel(text)
combobox = QComboBox()
if tip is not None:
combobox.setToolTip(tip)
for name, key in choices:
combobox.addItem(name, to_qvariant(key))
self.comboboxes[combobox] = (option, default)
layout = QHBoxLayout()
for subwidget in (label, combobox):
layout.addWidget(subwidget)
layout.addStretch(1)
layout.setContentsMargins(0, 0, 0, 0)
widget = QWidget(self)
widget.setLayout(layout)
return widget
示例4: create_combobox
# 需要导入模块: from spyderlib.qt.QtGui import QComboBox [as 别名]
# 或者: from spyderlib.qt.QtGui.QComboBox import addItem [as 别名]
def create_combobox(self, text, choices, option, default=NoDefault,
tip=None, restart=False):
"""choices: couples (name, key)"""
label = QLabel(text)
combobox = QComboBox()
if tip is not None:
combobox.setToolTip(tip)
for name, key in choices:
combobox.addItem(name, to_qvariant(key))
self.comboboxes[combobox] = (option, default)
layout = QHBoxLayout()
layout.addWidget(label)
layout.addWidget(combobox)
layout.addStretch(1)
layout.setContentsMargins(0, 0, 0, 0)
widget = QWidget(self)
widget.label = label
widget.combobox = combobox
widget.setLayout(layout)
combobox.restart_required = restart
combobox.label_text = text
return widget
示例5: RunConfigDialog
# 需要导入模块: from spyderlib.qt.QtGui import QComboBox [as 别名]
# 或者: from spyderlib.qt.QtGui.QComboBox import addItem [as 别名]
class RunConfigDialog(QDialog, SizeMixin):
"""Run configuration dialog box: multiple file version"""
def __init__(self, parent=None):
QDialog.__init__(self, parent)
SizeMixin.__init__(self)
# Destroying the C++ object right after closing the dialog box,
# otherwise it may be garbage-collected in another QThread
# (e.g. the editor's analysis thread in Spyder), thus leading to
# a segmentation fault on UNIX or an application crash on Windows
self.setAttribute(Qt.WA_DeleteOnClose)
self.file_to_run = None
combo_label = QLabel(_("Select a run configuration:"))
self.combo = QComboBox()
self.combo.setMaxVisibleItems(20)
self.combo.setSizeAdjustPolicy(QComboBox.AdjustToMinimumContentsLength)
self.combo.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
self.stack = QStackedWidget()
bbox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
run_btn = bbox.addButton(_("Run"), QDialogButtonBox.AcceptRole)
self.connect(run_btn, SIGNAL("clicked()"), self.run_btn_clicked)
self.connect(bbox, SIGNAL("accepted()"), SLOT("accept()"))
self.connect(bbox, SIGNAL("rejected()"), SLOT("reject()"))
btnlayout = QHBoxLayout()
btnlayout.addStretch(1)
btnlayout.addWidget(bbox)
layout = QVBoxLayout()
layout.addWidget(combo_label)
layout.addWidget(self.combo)
layout.addSpacing(10)
layout.addWidget(self.stack)
layout.addLayout(btnlayout)
self.setLayout(layout)
self.setWindowTitle(_("Run configurations"))
self.setWindowIcon(get_icon("run.png"))
def setup(self, fname):
configurations = _get_run_configurations()
for index, (filename, options) in enumerate(configurations):
if fname == filename:
break
else:
# There is no run configuration for script *fname*:
# creating a temporary configuration that will be kept only if
# dialog changes are accepted by the user
configurations.insert(0, (fname, RunConfiguration(fname).get()))
index = 0
for filename, options in configurations:
widget = RunConfigOptions(self)
widget.set(options)
self.combo.addItem(filename)
self.stack.addWidget(widget)
self.connect(self.combo, SIGNAL("currentIndexChanged(int)"), self.stack.setCurrentIndex)
self.combo.setCurrentIndex(index)
def accept(self):
"""Reimplement Qt method"""
configurations = []
for index in range(self.stack.count()):
filename = unicode(self.combo.itemText(index))
runconfigoptions = self.stack.widget(index)
if not runconfigoptions.is_valid():
return
options = runconfigoptions.get()
configurations.append((filename, options))
_set_run_configurations(configurations)
QDialog.accept(self)
def run_btn_clicked(self):
self.file_to_run = unicode(self.combo.currentText())