本文整理汇总了Python中PyQt5.QtWidgets.QListView.setSelection方法的典型用法代码示例。如果您正苦于以下问题:Python QListView.setSelection方法的具体用法?Python QListView.setSelection怎么用?Python QListView.setSelection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QListView
的用法示例。
在下文中一共展示了QListView.setSelection方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ConfigurationView
# 需要导入模块: from PyQt5.QtWidgets import QListView [as 别名]
# 或者: from PyQt5.QtWidgets.QListView import setSelection [as 别名]
class ConfigurationView(QWidget):
"""
Displays the configuration view.
"""
def __init__(self, parent=None):
super(ConfigurationView, self).__init__(parent)
self._layout = QBoxLayout(QBoxLayout.TopToBottom)
self.setLayout(self._layout)
self._editView = EditView(parent)
# initialize list view
self._listView = QListView()
self._configuration_model = self._get_config_model()
self._listView.setModel(self._configuration_model)
# initialize detail view
self._detailView = QWidget()
self._detailLayout = QBoxLayout(QBoxLayout.TopToBottom)
self._detailView.setLayout(self._detailLayout)
self._detailPanels = {}
self._currentDetailPanel = None
self._currentConfiguration = None # type: Configuration
self._config_wide_print_amounts = {}
self._recalculateEffectivePrintAmounts = False
# add widgets to layout
self._layout.addWidget(QLabel("List of Configurations"))
self._layout.addWidget(self._listView)
self._layout.addWidget(self._detailView)
self._create_detail_view()
# hide detail view on start
self._detailView.hide()
# selected configs map
self._selected_configs = {}
self._selected_counter = 0
# add event listener for selection change
self._listView.clicked.connect(self._on_selection_change)
self._listView.selectionModel().currentChanged.connect(self._on_selection_change)
def add_configuration(self, configuration):
"""
Adds the given configuration to the list view and opens the edit view.
:param configuration:
:type configuration: Configuration
"""
item = create_new_list_item(configuration.get_name())
self._configuration_model.appendRow(item)
self._editView.show_for_configuration(configuration)
def select_first_item(self):
rect = QRect(0,0,1,1)
self._listView.setSelection(rect, QItemSelectionModel.Select)
def update_model(self):
self._configuration_model = self._get_config_model()
self._listView.setModel(self._configuration_model)
@staticmethod
def _get_config_model():
data = DataStorage()
configurations_order = data.get_configurations_order()
model = QStandardItemModel()
for name in configurations_order:
item = create_new_list_item(name)
model.appendRow(item)
return model
def _on_selection_change(self, model_index):
"""
Called on selecting a new item in the listView.
:param model_index: index of selected item
:type model_index: QModelIndex
"""
data = DataStorage()
configurations = data.get_configurations()
selected_item = self._configuration_model.itemFromIndex(model_index) # type: QStandardItem
current_config_name = selected_item.text()
current_config = configurations[current_config_name] # type: Configuration
self._show_detail_view(current_config)
config_wide_print_amount = self._config_wide_print_amounts[current_config_name]
material_print_amounts = current_config.get_effective_material_print_amounts(
config_wide_print_amount,
self._recalculateEffectivePrintAmounts
)
self._recalculateEffectivePrintAmounts = False
if self._selected_counter == 0:
MaterialView.reset_check_state_and_print_amount()
for material in current_config.get_materials():
item = get_item(MaterialView.get_model().invisibleRootItem(), material.get_name())
if item is not None:
print_amount = material_print_amounts[material.get_name()]
if is_checked(selected_item):
check_item(item)
#.........这里部分代码省略.........