def __init__(self, df, parent, *args, **kwargs): """ Parameters ---------- %(DataFrameModel.parameters)s """ QTableView.__init__(self, parent) model = DataFrameModel(df, parent, *args, **kwargs) self.setModel(model) self.menu = self.setup_menu() self.frozen_table_view = FrozenTableView(self) self.frozen_table_view.update_geometry() self.setHorizontalScrollMode(1) self.setVerticalScrollMode(1) self.horizontalHeader().sectionResized.connect( self.update_section_width) self.verticalHeader().sectionResized.connect( self.update_section_height) self.sort_old = [None] self.header_class = self.horizontalHeader() self.header_class.sectionClicked.connect(self.sortByColumn) self.frozen_table_view.horizontalHeader().sectionClicked.connect( self.sortByColumn) self.horizontalScrollBar().valueChanged.connect( lambda val: self.load_more_data(val, columns=True)) self.verticalScrollBar().valueChanged.connect( lambda val: self.load_more_data(val, rows=True))
def __init__(self, marks, full_df, *args, **kwargs): """ Parameters ---------- marks: list of :class:`straditize.cross_mark.CrossMarks` the initial marks full_df: pandas.DataFrame The data fame of the full digitized data %(MultiCrossMarksModel.parameters.no_marks)s """ QTableView.__init__(self) self.full_df = full_df model = self.init_model(marks, *args, **kwargs) self.setModel(model) self.menu = self.setup_menu() self.frozen_table_view = FrozenTableView(self) self.frozen_table_view.update_geometry() self.setHorizontalScrollMode(1) self.setVerticalScrollMode(1) self.horizontalHeader().sectionResized.connect( self.update_section_width) self.verticalHeader().sectionResized.connect( self.update_section_height) self.header_class = self.horizontalHeader()
def __init__(self, parent): """Constructor.""" QTableView.__init__(self, parent) self.parent = parent self.setModel(parent.model()) self.setFocusPolicy(Qt.NoFocus) self.verticalHeader().hide() if with_qt5: self.horizontalHeader().setSectionResizeMode(QHeaderView.Fixed) else: self.horizontalHeader().setResizeMode(QHeaderView.Fixed) parent.viewport().stackUnder(self) self.setSelectionModel(parent.selectionModel()) for col in range(1, parent.model().columnCount()): self.setColumnHidden(col, True) self.setColumnWidth(0, parent.columnWidth(0)) self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.show() self.setVerticalScrollMode(QTableView.ScrollPerPixel) self.verticalScrollBar().valueChanged.connect( parent.verticalScrollBar().setValue) parent.verticalScrollBar().valueChanged.connect( self.verticalScrollBar().setValue)
def resizeEvent(self, event): """Update the frozen column dimensions. Updates takes place when the enclosing window of this table reports a dimension change """ QTableView.resizeEvent(self, event) self.frozen_table_view.update_geometry()
def scrollTo(self, index, hint): """Scroll the table. It is necessary to ensure that the item at index is visible. The view will try to position the item according to the given hint. This method does not takes effect only if the frozen column is scrolled. """ if index.column() > 1: QTableView.scrollTo(self, index, hint)
def moveCursor(self, cursor_action, modifiers): """Update the table position. Updates the position along with the frozen column when the cursor (selector) changes its position """ current = QTableView.moveCursor(self, cursor_action, modifiers) col_width = (self.columnWidth(0) + self.columnWidth(1)) topleft_x = self.visualRect(current).topLeft().x() overflow = self.MoveLeft and current.column() > 1 overflow = overflow and topleft_x < col_width if cursor_action == overflow: new_value = (self.horizontalScrollBar().value() + topleft_x - col_width) self.horizontalScrollBar().setValue(new_value) return current