def setup_export_panel(self): self.export_panel = w = QWidget(self) self.stack.addWidget(w) w.l = l = QVBoxLayout(w) w.la = la = QLabel( _('Select which libraries you want to export below')) la.setWordWrap(True), l.addWidget(la) self.lib_list = ll = QListWidget(self) l.addWidget(ll) ll.setSelectionMode(QAbstractItemView.SelectionMode.ExtendedSelection) ll.setStyleSheet('QListView::item { padding: 5px }') ll.setAlternatingRowColors(True) lpaths = all_known_libraries() for lpath in sorted( lpaths, key=lambda x: numeric_sort_key(os.path.basename(x))): i = QListWidgetItem(self.export_lib_text(lpath), ll) i.setData(Qt.ItemDataRole.UserRole, lpath) i.setData(Qt.ItemDataRole.UserRole + 1, lpaths[lpath]) i.setIcon(QIcon(I('lt.png'))) i.setSelected(True) self.update_disk_usage.connect( (lambda i, sz: self.lib_list.item(i).setText( self.export_lib_text( self.lib_list.item(i).data(Qt.ItemDataRole.UserRole), sz)) ), type=Qt.ConnectionType.QueuedConnection)
def updateWarriorList (self): row = 0 self.item = [] #self.tableWidget.clear() self.list_filtered.clear() for warrior in self.model.filteredWarriors() : item = QListWidgetItem (str(warrior.name)) item.setData(5,warrior) self.list_filtered.addItem(item) if warrior.selected == True: item.setSelected(True)
def _refillData(self): widget = self.widget oldBlockSignals = widget.blockSignals(True) oldAutoScroll = widget.hasAutoScroll() widget.setAutoScroll(False) # Scroll preserving code. From # https://stackoverflow.com/questions/34237006/qlistview-how-to-automatically-scroll-the-view-and-keep-current-selection-on-co vScrollBar = widget.verticalScrollBar() previousViewTopRow = widget.indexAt(QPoint(4, 4)).row() hasScrolledToBottom = vScrollBar.value() == vScrollBar.maximum() oldSelect = self.select() if oldSelect is None: oldSelect = [] elif not self._multiselect: oldSelect = [oldSelect] widget.clear() for d in self._data: item = QListWidgetItem() item.setText(self._renderer(d)) item.setData(Qt.UserRole, d) widget.addItem(item) if d in oldSelect: item.setSelected(True) if self._sorted: widget.sortItems() widget.scrollToTop() topIndex = widget.indexAt(QPoint(4, 4)) widget.setAutoScroll( oldAutoScroll ) # Re-enable autoscroll before scrolling to appropriate position if hasScrolledToBottom: widget.scrollToBottom() else: widget.scrollTo(topIndex.sibling(previousViewTopRow, 0), QAbstractItemView.PositionAtTop) widget.blockSignals(oldBlockSignals) # Actually we should check that same set of items were selected before & after the change, # but widget only selects less when underlying data changes, so no more data could be # selected any other than oldSelect. So it's sufficient to only check the length to # see if two list are same irrespective of orderings. if len(widget.selectedItems()) != len(oldSelect): self.widget.itemSelectionChanged.emit()
def setup_export_panel(self): self.export_panel = w = QWidget(self) self.stack.addWidget(w) w.l = l = QVBoxLayout(w) w.la = la = QLabel(_('Select which libraries you want to export below')) la.setWordWrap(True), l.addWidget(la) self.lib_list = ll = QListWidget(self) l.addWidget(ll) ll.setSelectionMode(ll.ExtendedSelection) ll.setStyleSheet('QListView::item { padding: 5px }') ll.setAlternatingRowColors(True) lpaths = all_known_libraries() for lpath in sorted(lpaths, key=lambda x:numeric_sort_key(os.path.basename(x))): i = QListWidgetItem(self.export_lib_text(lpath), ll) i.setData(Qt.UserRole, lpath) i.setData(Qt.UserRole+1, lpaths[lpath]) i.setIcon(QIcon(I('lt.png'))) i.setSelected(True) self.update_disk_usage.connect(( lambda i, sz: self.lib_list.item(i).setText(self.export_lib_text(self.lib_list.item(i).data(Qt.UserRole), sz))), type=Qt.QueuedConnection)
def _populate_list(self, list_widget, list_names, set_selected=True): list_widget.clear() for list_name in list_names: item = QListWidgetItem(list_name, list_widget) list_widget.addItem(item) item.setSelected(set_selected)