def __init__( self, displayed_columns: Sequence[Column], color: QtGui.QColor, parent: QtWidgets.QWidget) -> None: super().__init__(parent) self._displayed_columns = displayed_columns self.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows) self.setSelectionMode(QtWidgets.QAbstractItemView.NoSelection) self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.customContextMenuRequested.connect(self._open_context_menu) self.setRootIsDecorated(False) self.setEditTriggers( QtWidgets.QAbstractItemView.EditKeyPressed | QtWidgets.QAbstractItemView.AnyKeyPressed | QtWidgets.QAbstractItemView.SelectedClicked | QtWidgets.QAbstractItemView.DoubleClicked) self.setAlternatingRowColors(True) palette = self.palette() base_color = color.lighter(115) palette.setColor(QtGui.QPalette.Base, base_color) palette.setColor(QtGui.QPalette.AlternateBase, color) self.setPalette(palette) self.setStyleSheet( "QHeaderView::section {" "background-color: rgb(114, 118, 138);" "border: none;" "}") self.header().setSortIndicatorShown(True) self.header().setSectionsClickable(True) self.setSortingEnabled(True) self.setItemsExpandable(False)
def drawSquare(self, painter, x, y, shape): """ Draws a square of a shape """ color = self.curPiece.COLOR_TABLE color = QColor(color[shape]) painter.fillRect(x + 1, y + 1, self.get_square_width() - 2, self.get_square_height() - 2, color) painter.setPen(color.lighter()) painter.drawLine(x, y + self.get_square_height() - 1, x, y) painter.drawLine(x, y, x + self.get_square_width() - 1, y) painter.setPen(color.darker()) painter.drawLine(x + 1, y + self.get_square_height() - 1, x + self.get_square_width() - 1, y + self.get_square_height() - 1) painter.drawLine(x + self.get_square_width() - 1, y + self.get_square_height() - 1, x + self.get_square_width() - 1, y + 1)