class QtComparePanel(QWidget): filterChanged = pyqtSignal(str) def __init__(self, parent=None): super(QtComparePanel, self).__init__(parent) self.visibility_flags = [] self.visibility_buttons = [] self.labels_projects = [] self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) self.setMinimumWidth(400) self.setMinimumHeight(100) self.data_table = QTableView() self.data_table.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) self.data_table.setSelectionMode(QAbstractItemView.MultiSelection) self.data_table.setSelectionMode(QAbstractItemView.ExtendedSelection) self.data_table.setSelectionBehavior(QAbstractItemView.SelectRows) self.model = None self.data = None self.combodelegate1 = ComboBoxItemDelegate(self.data_table) self.combodelegate2 = ComboBoxItemDelegate(self.data_table) lblFilter = QLabel("Filter: ") self.comboboxFilter = QComboBox() self.comboboxFilter.setMinimumWidth(80) self.comboboxFilter.addItem("All") self.comboboxFilter.addItem("Same") self.comboboxFilter.addItem("Born") self.comboboxFilter.addItem("Dead") self.comboboxFilter.addItem("Grow") self.comboboxFilter.addItem("Shrink") filter_layout = QHBoxLayout() filter_layout.addWidget(lblFilter) filter_layout.addWidget(self.comboboxFilter) filter_layout.addStretch() layout = QVBoxLayout() layout.addLayout(filter_layout) layout.addWidget(self.data_table) self.setLayout(layout) self.correspondences = None self.data = None self.comboboxFilter.currentTextChanged.connect(self.changeFilter) def setTable(self, project, img1idx, img2idx): self.correspondences = project.getImagePairCorrespondences( img1idx, img2idx) self.data = self.correspondences.data self.model = TableModel(self.data) self.sortfilter = QSortFilterProxyModel(self) self.sortfilter.setSourceModel(self.model) self.data_table.setModel(self.sortfilter) self.data_table.setVisible(False) self.data_table.verticalHeader().hide() self.data_table.resizeColumnsToContents() self.data_table.setVisible(True) self.data_table.setItemDelegateForColumn(5, self.combodelegate1) self.data_table.setItemDelegateForColumn(6, self.combodelegate2) self.data_table.setEditTriggers(QAbstractItemView.DoubleClicked) self.data_table.update() self.data_table.setStyleSheet( "QHeaderView::section { background-color: rgb(40,40,40) }") def updateData(self, corr): if corr is None: return self.correspondences = corr self.sortfilter.beginResetModel() self.model.beginResetModel() self.model._data = corr.data self.sortfilter.endResetModel() self.model.endResetModel() self.data_table.update() def selectRows(self, rows): self.data_table.clearSelection() indexes = [self.model.index(r, 0) for r in rows] mode = QItemSelectionModel.Select | QItemSelectionModel.Rows [ self.data_table.selectionModel().select(index, mode) for index in indexes ] if len(rows) > 0: value = self.data_table.horizontalScrollBar().value() column = self.data_table.columnAt(value) self.data_table.scrollTo(self.data_table.model().index( rows[0], column)) @pyqtSlot(QModelIndex) def getData(self, index): pass #column = index.column() #row = index.row() #self.data_table.model().index(row, column).data() @pyqtSlot(str) def changeFilter(self, txt): if self.data is None: return if txt == 'All': self.sortfilter.setFilterRegExp(QRegExp()) else: self.sortfilter.setFilterKeyColumn(5) self.sortfilter.setFilterRegExp(txt.lower()) self.sortfilter.setFilterRole(Qt.DisplayRole) self.filterChanged.emit(txt.lower())