Пример #1
0
 def select_row(self, row_index):
     selection = self.selection_model
     model = self.model()
     index1 = model.index(row_index, 0)
     index2 = model.index(row_index, model.columnCount() - 1)
     selection.select(QtCore.QItemSelection(index1, index2),
                      QtCore.QItemSelectionModel.Select)
Пример #2
0
 def select_item(self, item):
     self.selection = self.selectionModel()
     self.selection.select(
         QtCore.QItemSelection(
             self.indexFromItem(item, 0),
             self.indexFromItem(item,
                                self.columnCount() - 1)),
         QtCore.QItemSelectionModel.ClearAndSelect)
Пример #3
0
 def _completions_updated(self):
     popup = self.popup()
     if not popup.isVisible():
         return
     # Select the first item
     idx = self._completion_model.index(0, 0)
     selection = QtCore.QItemSelection(idx, idx)
     mode = QtCore.QItemSelectionModel.Select
     popup.selectionModel().select(selection, mode)
Пример #4
0
 def moveSelectionUp(self, selectionmodel):
     # assert selectionmodel.model() is self.model
     selection = selectionmodel.selection()
     selectionmap = self._selectionmap(selection)
     newselection = QtCore.QItemSelection()
     for parent, ranges in selectionmap.items():
         for selectionrange in ranges:
             dst = selectionrange.top() - 1
             newrange = self._moveSelectionRange(selectionrange, dst)
             newselection.append(newrange)
     selectionmodel.select(newselection, SelectCurrentRows)
Пример #5
0
 def moveSelectionToTop(self, selectionmodel):
     # assert selectionmodel.model() is self.model
     selection = selectionmodel.selection()
     selectionmap = self._selectionmap(selection)
     newselection = QtCore.QItemSelection()
     for parent, ranges in selectionmap.items():
         dst = 0
         for selectionrange in ranges:
             newrange = self._moveSelectionRange(selectionrange, dst)
             newselection.append(newrange)
             dst = newrange.bottom() + 1
     selectionmodel.select(newselection, SelectCurrentRows)
Пример #6
0
 def moveSelectionToBottom(self, selectionmodel):
     # assert selectionmodel.model() is self.model
     selection = selectionmodel.selection()
     selectionmap = self._selectionmap(selection)
     newselection = QtCore.QItemSelection()
     nrows = selectionmodel.model().rowCount()
     for parent, ranges in selectionmap.items():
         ranges.reverse()
         dst = nrows
         for selectionrange in ranges:
             dst -= selectionrange.height()
             newrange = self._moveSelectionRange(selectionrange, dst)
             newselection.append(newrange)
     selectionmodel.select(newselection, SelectCurrentRows)
Пример #7
0
def selectAllItems(itemview):
    """Select all items in an QAbstractItemView."""

    model = itemview.model()
    topleft = model.index(0, 0)

    try:
        bottomright = model.index(model.rowCount() - 1,
                                  model.columnCount() - 1)
    except (TypeError, AttributeError):
        # columnCount is a private method in QAbstractListModel
        # assume it is a list
        bottomright = model.index(model.rowCount() - 1)

    selection = QtCore.QItemSelection(topleft, bottomright)
    itemview.selectionModel().select(selection,
                                     QtCore.QItemSelectionModel.Select)