本文整理汇总了Python中PyQt5.QtWidgets.QListView.data方法的典型用法代码示例。如果您正苦于以下问题:Python QListView.data方法的具体用法?Python QListView.data怎么用?Python QListView.data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QListView
的用法示例。
在下文中一共展示了QListView.data方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ListScrollArea
# 需要导入模块: from PyQt5.QtWidgets import QListView [as 别名]
# 或者: from PyQt5.QtWidgets.QListView import data [as 别名]
class ListScrollArea(QVBoxLayout):
def __init__(self, parent):
QVBoxLayout.__init__(self, parent)
self.scroll_area = QScrollArea()
# A ListView is a widget, instead of a layout, so there should be no need for additional containers
self.list_view = QListView()
self.scroll_area.setWidget(self.list_view)
self.addWidget(self.list_view)
self.view_model = QStringListModel()
self.list_view.setModel(self.view_model)
def add_item_by_string(self, value):
current_values = self.view_model.stringList()
if value not in current_values:
current_values.append(value)
self.view_model.setStringList(current_values)
def remove_item_by_string(self, value):
current_values = self.view_model.stringList()
if value in current_values:
current_values.remove(value)
self.view_model.setStringList(current_values)
def clear_all(self):
self.view_model.setStringList([])
def get_currently_selected_item(self):
currently_selected_item_index = self.view_model.currentIndex()
currently_selected_item_text = str(self.list_view.data(currently_selected_item_index))
return currently_selected_item_text
def get_item(self, index):
current_values = self.view_model.stringList()
if index < len(current_values):
return current_values[index]
return None
def get_num_items(self):
return len(self.view_model.stringList())