Exemple #1
0
 def paintHorizontalSection(self, painter: QPainter, sectionRect: QRect,
                            logicalLeafIndex: int, hv: QHeaderView,
                            styleOptions: QStyleOptionHeader,
                            leafIndex: QModelIndex):
     #            print(logicalLeafIndex)
     oldBO = painter.brushOrigin()
     top = sectionRect.y()
     indexes = QModelIndexList(self.parentIndexes(leafIndex))
     for i in range(indexes.size()):
         realStyleOptions = QStyleOptionHeader(styleOptions)
         if i < indexes.size() - 1 and (
                 realStyleOptions.state & QStyle.State_Sunken
                 or realStyleOptions.state & QStyle.State_On):
             t = QStyle.State(QStyle.State_Sunken | QStyle.State_On)
             realStyleOptions.state = realStyleOptions.state & ~t  # FIXME: parent items are not highlighted
         if i < indexes.size(
         ) - 1:  # Use sortIndicator for inner level only
             realStyleOptions.sortIndicator = False
         # if i==0:
         #                    print(self.leafs(indexes[i]), leafIndex)
         top = self.paintHorizontalCell(painter, hv, indexes[i],
                                        leafIndex, logicalLeafIndex,
                                        realStyleOptions, sectionRect,
                                        top)
     painter.setBrushOrigin(oldBO)
Exemple #2
0
 def paintVerticalSection(self, painter: QPainter, sectionRect: QRect,
                          logicalLeafIndex: int, hv: QHeaderView,
                          styleOptions: QStyleOptionHeader,
                          leafIndex: QModelIndex):
     oldBO = painter.brushOrigin()
     left = sectionRect.x()
     indexes = QModelIndexList(self.parentIndexes(leafIndex))
     for i in range(indexes.size()):
         realStyleOptions = QStyleOptionHeader(styleOptions)
         if i < indexes.size() - 1 and (
                 realStyleOptions.state & QStyle.State_Sunken
                 or realStyleOptions.state & QStyle.State_On):
             t = QStyle.State(QStyle.State_Sunken | QStyle.State_On)
             realStyleOptions.state = realStyleOptions.state & ~t  # FIXME: parent items are not highlighted
         left = self.paintVerticalCell(painter, hv, indexes[i],
                                       leafIndex, logicalLeafIndex,
                                       realStyleOptions, sectionRect,
                                       left)
     painter.setBrushOrigin(oldBO)
Exemple #3
0
 def styleOptionForCell(self, logicalInd: int) -> QStyleOptionHeader:
     opt = QStyleOptionHeader()
     self.initStyleOption(opt)
     if self.isSortIndicatorShown() and self.sortIndicatorSection(
     ) == logicalInd:
         opt.sortIndicator = (
             QStyleOptionHeader.SortUp, QStyleOptionHeader.SortDown
         )[self.sortIndicatorOrder() == Qt.AscendingOrder]
     if self.window().isActiveWindow():
         opt.state = opt.state | QStyle.State_Active
     opt.textAlignment = Qt.AlignCenter
     opt.iconAlignment = Qt.AlignVCenter
     opt.section = logicalInd
     visual = self.visualIndex(logicalInd)
     if self.count() == 1:
         opt.position = QStyleOptionHeader.OnlyOneSection
     else:
         if visual == 0:
             opt.position = QStyleOptionHeader.Beginning
         else:
             opt.position = QStyleOptionHeader.End if visual == self.count(
             ) - 1 else QStyleOptionHeader.Middle
     if self.isClickable():
         #            if logicalIndex == d.hover:
         #            ...
         if self.highlightSections() and self.selectionModel():
             if self.orientation() == Qt.Horizontal:
                 if self.selectionModel().columnIntersectsSelection(
                         logicalInd, self.rootIndex()):
                     opt.state = opt.state | QStyle.State_On
                 if self.selectionModel().isColumnSelected(
                         logicalInd, self.rootIndex()):
                     opt.state = opt.state | QStyle.State_Sunken
             else:
                 if self.selectionModel().rowIntersectsSelection(
                         logicalInd, self.rootIndex()):
                     opt.state = opt.state | QStyle.State_On
                 if self.selectionModel().isRowSelected(
                         logicalInd, self.rootIndex()):
                     opt.state = opt.state | QStyle.State_Sunken
     if self.selectionModel():
         previousSelected = False
         if self.orientation() == Qt.Horizontal:
             previousSelected = self.selectionModel().isColumnSelected(
                 self.logicalIndex(visual - 1), self.rootIndex())
         else:
             previousSelected = self.selectionModel().isRowSelected(
                 self.logicalIndex(visual - 1), self.rootIndex())
         nextSelected = False
         if self.orientation() == Qt.Horizontal:
             nextSelected = self.selectionModel().isColumnSelected(
                 self.logicalIndex(visual + 1), self.rootIndex())
         else:
             nextSelected = self.selectionModel().isRowSelected(
                 self.logicalIndex(visual + 1), self.rootIndex())
         if previousSelected and nextSelected:
             opt.selectedPosition = QStyleOptionHeader.NextAndPreviousAreSelected
         else:
             if previousSelected:
                 opt.selectedPosition = QStyleOptionHeader.PreviousIsSelected
             else:
                 if nextSelected:
                     opt.selectedPosition = QStyleOptionHeader.NextIsSelected
                 else:
                     opt.selectedPosition = QStyleOptionHeader.NotAdjacent
     return opt