Skip to content

OrientedTableView

Qt Base Class: QTableView

Signature: QTableView(self, parent: Optional[PySide6.QtWidgets.QWidget] = None) -> None

Base classes

Name Children Inherits
TableView
prettyqt.widgets.tableview

⋔ Inheritance diagram

graph TD
  1473367046240["custom_widgets.OrientedTableView"]
  1473296359344["widgets.TableView"]
  1473296352512["widgets.TableViewMixin"]
  1473293692144["widgets.AbstractItemViewMixin"]
  1473293679456["widgets.AbstractScrollAreaMixin"]
  1473293662864["widgets.FrameMixin"]
  1473293688240["widgets.WidgetMixin"]
  1473299815024["core.ObjectMixin"]
  140713234304496["builtins.object"]
  1473245548480["gui.PaintDeviceMixin"]
  1473241449136["QtWidgets.QTableView"]
  1473241438400["QtWidgets.QAbstractItemView"]
  1473290616416["QtWidgets.QAbstractScrollArea"]
  1473290626176["QtWidgets.QFrame"]
  1473290849680["QtWidgets.QWidget"]
  1473288842240["QtCore.QObject"]
  1473291690208["Shiboken.Object"]
  1473300082368["QtGui.QPaintDevice"]
  1473296359344 --> 1473367046240
  1473296352512 --> 1473296359344
  1473293692144 --> 1473296352512
  1473293679456 --> 1473293692144
  1473293662864 --> 1473293679456
  1473293688240 --> 1473293662864
  1473299815024 --> 1473293688240
  140713234304496 --> 1473299815024
  1473245548480 --> 1473293688240
  140713234304496 --> 1473245548480
  1473241449136 --> 1473296359344
  1473241438400 --> 1473241449136
  1473290616416 --> 1473241438400
  1473290626176 --> 1473290616416
  1473290849680 --> 1473290626176
  1473288842240 --> 1473290849680
  1473291690208 --> 1473288842240
  140713234304496 --> 1473291690208
  1473300082368 --> 1473290849680
  1473291690208 --> 1473300082368

🛈 DocStrings

Bases: TableView

TableView class with some convenience methods for oriented tables.

Source code in prettyqt\custom_widgets\orientedtableview.py
class OrientedTableView(widgets.TableView):
    """TableView class with some convenience methods for oriented tables."""

    def __init__(
        self, orientation: constants.Orientation | constants.OrientationStr, **kwargs
    ):
        super().__init__(**kwargs)
        self.orientation = constants.ORIENTATION.get_enum_value(orientation)

    @classmethod
    def setup_example(cls):
        return cls(orientation="vertical")

    def get_higher_levels(self, levels: int) -> core.ItemSelection:
        model = self.model()
        if self.is_horizontal():
            # Get the header's selected columns
            # Removes the higher levels so that only the lowest level of the header
            # affects the data table selection
            return core.ItemSelection(
                model.index(0, 0), model.index(levels - 2, model.columnCount() - 1)
            )
        else:
            return core.ItemSelection(
                model.index(0, 0), model.index(model.rowCount() - 1, levels - 2)
            )

    def set_section_span(self, row: int, column: int, count: int):
        if self.is_horizontal():
            self.setSpan(row, column, 1, count)
        else:
            self.setSpan(column, row, count, 1)

    def sectionAt(self, val: int):
        return self.columnAt(val) if self.is_horizontal() else self.rowAt(val)

    def over_header_edge(self, position: int, margin: int = 3) -> int:
        # Return the index of the column this x position is on the right edge of
        left = self.sectionAt(position - margin)
        right = self.sectionAt(position + margin)
        if left != right != 0:
            # We're at the left edge of the first column
            return left

    def is_horizontal(self) -> bool:
        return self.orientation == constants.HORIZONTAL

    def sectionWidth(self, val: int):
        return self.columnWidth(val) if self.is_horizontal() else self.rowHeight(val)

    def setSectionWidth(self, section: int, width: int):
        if self.is_horizontal():
            self.setColumnWidth(section, width)
        else:
            self.setRowHeight(section, width)

    def get_split_cursor(self) -> gui.Cursor:
        if self.is_horizontal():
            return gui.Cursor(constants.CursorShape.SplitHCursor)
        else:
            return gui.Cursor(constants.CursorShape.SplitVCursor)

⌗ Property table

Qt Property Type Doc
objectName QString
modal bool
windowModality Qt::WindowModality
enabled bool
geometry QRect
frameGeometry QRect
normalGeometry QRect
x int
y int
pos QPoint
frameSize QSize
size QSize
width int
height int
rect QRect
childrenRect QRect
childrenRegion QRegion
sizePolicy QSizePolicy
minimumSize QSize
maximumSize QSize
minimumWidth int
minimumHeight int
maximumWidth int
maximumHeight int
sizeIncrement QSize
baseSize QSize
palette QPalette
font QFont
cursor QCursor
mouseTracking bool
tabletTracking bool
isActiveWindow bool
focusPolicy Qt::FocusPolicy
focus bool
contextMenuPolicy Qt::ContextMenuPolicy
updatesEnabled bool
visible bool
minimized bool
maximized bool
fullScreen bool
sizeHint QSize
minimumSizeHint QSize
acceptDrops bool
windowTitle QString
windowIcon QIcon
windowIconText QString
windowOpacity double
windowModified bool
toolTip QString
toolTipDuration int
statusTip QString
whatsThis QString
accessibleName QString
accessibleDescription QString
layoutDirection Qt::LayoutDirection
autoFillBackground bool
styleSheet QString
locale QLocale
windowFilePath QString
inputMethodHints QFlags
frameShape QFrame::Shape
frameShadow QFrame::Shadow
lineWidth int
midLineWidth int
frameWidth int
frameRect QRect
verticalScrollBarPolicy Qt::ScrollBarPolicy
horizontalScrollBarPolicy Qt::ScrollBarPolicy
sizeAdjustPolicy QAbstractScrollArea::SizeAdjustPolicy
autoScroll bool
autoScrollMargin int
editTriggers QFlags
tabKeyNavigation bool
showDropIndicator bool
dragEnabled bool
dragDropOverwriteMode bool
dragDropMode QAbstractItemView::DragDropMode
defaultDropAction Qt::DropAction
alternatingRowColors bool
selectionMode QAbstractItemView::SelectionMode
selectionBehavior QAbstractItemView::SelectionBehavior
iconSize QSize
textElideMode Qt::TextElideMode
verticalScrollMode QAbstractItemView::ScrollMode
horizontalScrollMode QAbstractItemView::ScrollMode
showGrid bool
gridStyle Qt::PenStyle
sortingEnabled bool
wordWrap bool
cornerButtonEnabled bool

🖼 Screenshot