def paintEvent(self, event):
     super().paintEvent(event)
     painter = QPainter(self)
     for top, _, block in self._neditor.visible_blocks:
         if not self.is_foldable_block(block):
             continue
         branch_rect = QRect(0, top,
                             self.sizeHint().width(),
                             self.sizeHint().height())
         opt = QStyleOptionViewItem()
         opt.rect = branch_rect
         opt.state = (QStyle.State_Active | QStyle.State_Item
                      | QStyle.State_Children)
         folded = self.user_data(block).get("folded", default=False)
         if not folded:
             opt.state |= QStyle.State_Open
         # Draw item
         self.style().drawPrimitive(QStyle.PE_IndicatorBranch, opt, painter,
                                    self)
         # Draw folded region background
         if block == self.__mouse_over and not self.__timer.isActive():
             fm_height = self._neditor.fontMetrics().height()
             rect_height = 0
             color = self.palette().highlight().color()
             color.setAlpha(100)
             if not folded:
                 foldable_blocks = self.code_folding.foldable_blocks(block)
                 rect_height = (len(list(foldable_blocks))) * fm_height
             painter.fillRect(
                 QRect(0, top,
                       self.sizeHint().width(), rect_height + fm_height),
                 color)
Пример #2
0
 def paintEvent(self, event):
     super().paintEvent(event)
     painter = QPainter(self)
     for top, _, block in self._neditor.visible_blocks:
         if not self.is_foldable_block(block):
             continue
         branch_rect = QRect(0, top, self.sizeHint().width(),
                             self.sizeHint().height())
         opt = QStyleOptionViewItem()
         opt.rect = branch_rect
         opt.state = (QStyle.State_Active |
                      QStyle.State_Item |
                      QStyle.State_Children)
         folded = self.user_data(block).get("folded", default=False)
         if not folded:
             opt.state |= QStyle.State_Open
         # Draw item
         self.style().drawPrimitive(QStyle.PE_IndicatorBranch, opt,
                                    painter, self)
         # Draw folded region background
         if block == self.__mouse_over and not self.__timer.isActive():
             fm_height = self._neditor.fontMetrics().height()
             rect_height = 0
             color = self.palette().highlight().color()
             color.setAlpha(100)
             if not folded:
                 foldable_blocks = self.code_folding.foldable_blocks(block)
                 rect_height = (len(list(foldable_blocks))) * fm_height
             painter.fillRect(QRect(
                 0, top, self.sizeHint().width(),
                 rect_height + fm_height), color)
Пример #3
0
 def paint(
         self,
         painter: QtGui.QPainter,
         item: QtWidgets.QStyleOptionViewItem,
         ix: QtCore.QModelIndex,
 ):
     if item.state & QtWidgets.QStyle.State_HasFocus:
         item.state = item.state ^ QtWidgets.QStyle.State_HasFocus
     super().paint(painter, item, ix)
Пример #4
0
 def paint(self, painter, option, index):
     item_option = QStyleOptionViewItem(option)
     if item_option.state and QStyle.State_HasFocus:
         item_option.state = item_option.state ^ QStyle.State_HasFocus
     # QStyledItemDelegate.paint(painter, item_option, index)
     super(NoFocusDelegate, self).paint(painter, item_option, index)