本文整理汇总了Python中AnyQt.QtWidgets.QComboBox.model方法的典型用法代码示例。如果您正苦于以下问题:Python QComboBox.model方法的具体用法?Python QComboBox.model怎么用?Python QComboBox.model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtWidgets.QComboBox
的用法示例。
在下文中一共展示了QComboBox.model方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RecentPathsWComboMixin
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import model [as 别名]
class RecentPathsWComboMixin(RecentPathsWidgetMixin):
"""
Adds file combo handling to :obj:`RecentPathsWidgetMixin`.
The mixin constructs a combo box `self.file_combo` and provides a method
`set_file_list` for updating its content. The mixin also overloads the
inherited `add_path` and `select_file` to call `set_file_list`.
"""
def __init__(self):
super().__init__()
self.file_combo = \
QComboBox(self, sizeAdjustPolicy=QComboBox.AdjustToContents)
def add_path(self, filename):
"""Add (or move) a file name to the top of recent paths"""
super().add_path(filename)
self.set_file_list()
def select_file(self, n):
"""Move the n-th file to the top of the list"""
super().select_file(n)
self.set_file_list()
def set_file_list(self):
"""
Sets the items in the file list combo
"""
self._check_init()
self.file_combo.clear()
if not self.recent_paths:
self.file_combo.addItem("(none)")
self.file_combo.model().item(0).setEnabled(False)
else:
for i, recent in enumerate(self.recent_paths):
self.file_combo.addItem(recent.basename)
self.file_combo.model().item(i).setToolTip(recent.abspath)
if not os.path.exists(recent.abspath):
self.file_combo.setItemData(i, QBrush(Qt.red),
Qt.TextColorRole)
def workflowEnvChanged(self, key, value, oldvalue):
super().workflowEnvChanged(key, value, oldvalue)
if key == "basedir":
self.set_file_list()
示例2: OWImportImages
# 需要导入模块: from AnyQt.QtWidgets import QComboBox [as 别名]
# 或者: from AnyQt.QtWidgets.QComboBox import model [as 别名]
#.........这里部分代码省略.........
vlayout = QVBoxLayout()
vlayout.setContentsMargins(0, 0, 0, 0)
hlayout = QHBoxLayout()
hlayout.setContentsMargins(0, 0, 0, 0)
hlayout.addWidget(self.progress_widget)
hlayout.addWidget(self.cancel_button)
vlayout.addLayout(hlayout)
self.pathlabel = TextLabel()
self.pathlabel.setTextElideMode(Qt.ElideMiddle)
self.pathlabel.setAttribute(Qt.WA_MacSmallSize)
vlayout.addWidget(self.pathlabel)
w.setLayout(vlayout)
self.infostack.addWidget(self.info_area)
self.infostack.addWidget(w)
box.layout().addWidget(self.infostack)
self.__initRecentItemsModel()
self.__invalidated = True
self.__executor = ThreadExecutor(self)
QApplication.postEvent(self, QEvent(RuntimeEvent.Init))
def __initRecentItemsModel(self):
self._relocate_recent_files()
recent_paths = []
for item in self.recent_paths:
recent_paths.append(item)
recent_paths = recent_paths[:OWImportImages.MaxRecentItems]
recent_model = self.recent_cb.model()
recent_model.clear()
for pathitem in recent_paths:
item = RecentPath_asqstandarditem(pathitem)
recent_model.appendRow(item)
self.recent_paths = recent_paths
if self.recent_paths and os.path.isdir(self.recent_paths[0].abspath):
self.recent_cb.setCurrentIndex(0)
self.__actions.reload.setEnabled(True)
else:
self.recent_cb.setCurrentIndex(-1)
self.__actions.reload.setEnabled(False)
def customEvent(self, event):
"""Reimplemented."""
if event.type() == RuntimeEvent.Init:
if self.__invalidated:
try:
self.start()
finally:
self.__invalidated = False
super().customEvent(event)
def __runOpenDialog(self):
startdir = os.path.expanduser("~/")
if self.recent_paths:
startdir = os.path.dirname(self.recent_paths[0].abspath)
if OWImportImages.Modality == Qt.WindowModal: