本文整理汇总了Python中PySide.QtGui.QComboBox.clear方法的典型用法代码示例。如果您正苦于以下问题:Python QComboBox.clear方法的具体用法?Python QComboBox.clear怎么用?Python QComboBox.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QComboBox
的用法示例。
在下文中一共展示了QComboBox.clear方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ChoiceField
# 需要导入模块: from PySide.QtGui import QComboBox [as 别名]
# 或者: from PySide.QtGui.QComboBox import clear [as 别名]
class ChoiceField(BaseInputField):
def __init__(self, choices, initial="", label=""):
super(ChoiceField, self).__init__(initial, label)
self._choices = choices
def create_widget(self, parent):
self._widget = QComboBox(parent)
self.update_view()
return self._widget
def update_view(self):
if isinstance(self._choices, list):
choices = self._choices
elif isinstance(self._choices, str):
choices = getattr(self.simple_widget, self._choices)
self._widget.clear()
self._widget.addItems([str(choice) for choice in choices])
if self.initial:
self._widget.setCurrentIndex(choices.index(self.initial))
def get_value_from(self, widget):
return widget.currentText()
示例2: qHotField
# 需要导入模块: from PySide.QtGui import QComboBox [as 别名]
# 或者: from PySide.QtGui.QComboBox import clear [as 别名]
class qHotField(QWidget):
def __init__(self, name, mytype, initial_value, value_list = None, pos = "left", help_text = None, help_instance = None, min_size = 0, max_size = None, handler = None, multiline=False):
QWidget.__init__(self)
if max_size == None:
max_size = 300
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) # Let it expand horizontally but not vertically
self.name = name
self.mytype = mytype
self.multiline = multiline
self.setContentsMargins(1, 1, 1, 1)
self.is_popup = (value_list != None)
if self.is_popup:
self.value_list = [str(v) for v in value_list] # It's possible the values won't be strings.
if pos == "top":
self.layout1 = QVBoxLayout()
else:
self.layout1=QHBoxLayout()
self.layout1.setContentsMargins(1, 1, 1, 1)
self.layout1.setSpacing(1)
self.setLayout(self.layout1)
if mytype == bool:
self.cb = QCheckBox(name)
self.cb.setFont(regular_small_font)
self.layout1.addWidget(self.cb)
self.cb.setChecked(initial_value)
if handler != None:
self.cb.toggled.connect(handler)
else:
if not self.is_popup:
if multiline:
self.efield=QPlainTextEdit("")
self.efield.appendPlainText(str(initial_value))
else:
self.efield = QLineEdit("Default Text")
self.efield.setText(str(initial_value))
if handler != None:
self.efield.textChanged.connect(handler)
else:
self.efield = QComboBox()
self.efield.addItems(value_list)
if len(value_list) != 0:
self.efield.setCurrentIndex(value_list.index(initial_value))
self.efield.setSizeAdjustPolicy(QComboBox.AdjustToContents)
if handler != None:
self.efield.currentIndexChanged.connect(handler)
self.layout1.setContentsMargins(5, 5, 5, 5) # Popups need a little more space
self.layout1.setSpacing(2)
self.efield.setFont(regular_small_font)
self.label = QLabel(name)
self.label.setFont(regular_small_font)
if pos == "right":
self.layout1.addWidget(self.efield)
self.layout1.addWidget(self.label)
else:
self.layout1.addWidget(self.label)
self.layout1.addWidget(self.efield)
self.efield.setMaximumWidth(max_size)
if min_size != 0:
self.efield.setMinimumWidth(min_size)
self.layout1.addStretch()
if help_text != None:
if (help_instance == None):
print "No help instance specified."
else:
help_button_widget = help_instance.create_button(name, help_text)
self.layout1.addWidget(help_button_widget)
def repopulate_list(self, initial_value, value_list):
if not self.is_popup:
print "This qHotField is not a popup list. So it can't be repopulated"
return
self.value_list = [str(v) for v in value_list] # It's possible the values won't be strings
self.efield.clear()
self.efield.addItems(value_list)
self.efield.setCurrentIndex(value_list.index(initial_value))
return
def get_myvalue(self):
if self.mytype == bool:
return self.cb.isChecked()
else:
if self.is_popup:
the_txt = self.efield.currentText()
else:
if self.multiline:
the_txt = self.efield.toPlainText()
else:
the_txt = self.efield.text()
if (self.mytype == str) or (self.mytype == unicode):
return (self.mytype)(the_txt)
else: # if we have a numerical type, the user might have entered a list separated by spaces. Handle that specially
the_val = re.findall(r"\S+", the_txt) # We might have a list of values separated by spaces if this is a numerical variable
if len(the_val) == 1: # it's just a single value
result = (self.mytype)(the_txt)
else: # it's a list. We want to convert treat this as a monte sequence
res = []
for v in the_val:
res.append((self.mytype)(v))
result = MonteSequence(res)
#.........这里部分代码省略.........
示例3: UiMain
# 需要导入模块: from PySide.QtGui import QComboBox [as 别名]
# 或者: from PySide.QtGui.QComboBox import clear [as 别名]
#.........这里部分代码省略.........
# fix for the Foobar double output problem.
self.switch_output_split_btn = QCheckBox(self.options)
self.switch_output_split_btn.setCheckState(Qt.CheckState.Unchecked)
self.switch_output_split_btn.setGeometry(10, 140, 40, 30)
self.switch_output_split_btn.stateChanged.connect(self.toggle_split)
# The label for the split toggle
self.switch_output_split_lbl = QLabel(self.options)
self.switch_output_split_lbl.setText(
"Split the output text in half (don't use this if you don't need it)")
self.switch_output_split_lbl.setGeometry(30, 140, 300, 30)
def switch_item_on(self):
""" Switches items (musicapps) on """
try:
# If an item from the active box is selected
# Remove it and place it inside the inactive box
item_taken = self.inactive_items_list.takeItem(
self.inactive_items_list.currentRow())
self.active_items_list.addItem(item_taken)
active_items = {}
inactive_items = {}
for i in range(self.active_items_list.count()):
active_items[self.active_items_list.item(i).text()] =\
ITEMS[self.active_items_list.item(i).text()
.encode('utf-8')]
for i in range(self.inactive_items_list.count()):
inactive_items[self.inactive_items_list.item(i).text()] =\
ITEMS[self.inactive_items_list.item(i).text()
.encode('utf-8')]
Constants.ACTIVE_ITEMS = active_items
Constants.INACTIVE_ITEMS = inactive_items
# clear the selection combobox
self.app_select_box.clear()
# Repopulate the combobox
self.app_select_box.addItem(None)
for item in active_items:
self.app_select_box.addItem(item)
Constants.CONFIG.set('active', item_taken.text(),
ITEMS[item_taken.text()])
Constants.CONFIG.remove_option('inactive', item_taken.text())
# Updates the config file to be up to date with activeItems
Constants.CONFIG.update()
except:
raise
def switch_item_off(self):
""" Switches items (musicapps) off """
try:
# If an item from the inactive box is selected.
# Remove it and place it inside the active box
item_taken = self.active_items_list.takeItem(
self.active_items_list.currentRow())
self.inactive_items_list.addItem(item_taken)
# update activeItems
active_items = {}
inactive_items = {}
for i in range(self.active_items_list.count()):
active_items[self.active_items_list.item(i).text()] =\
ITEMS[self.active_items_list.item(i).text()
.encode('utf-8')]
for i in range(self.inactive_items_list.count()):
inactive_items[self.inactive_items_list.item(i).text()] =\
ITEMS[self.inactive_items_list.item(i).text()
.encode('utf-8')]
Constants.ACTIVE_ITEMS = active_items