def paint(self, painter, option, index):
     '''
     This pure abstract function must be reimplemented if you
     want to provide custom rendering. Use the painter and style
     option to render the item specified by the item index
     '''
     painter.save()
     options = QStyleOptionViewItem(option)
     # get the cell text
     options.text = index.data()
     # get the cell rectangle
     rt = QRect(options.rect)
     # determines the cell is selected or not
     flag = False
     if option.state & QStyle.State_Selected:
         flag = True
     # sets back/fore color for selected/non-selected
     back_color = Qt.white if not flag else QColor('#0087D0')
     fore_color = Qt.black if not flag else Qt.white
     # paint the backgrouund
     painter.fillRect(rt, back_color)
     # select the pen for draw text
     painter.setPen(QColor(fore_color))
     # make the margin
     rt.adjust(10, 0, 0, 10)
     # draw the text
     painter.drawText(rt, self.m_TextAlign, options.text)
     painter.restore()
示例#2
0
文件: geometry.py 项目: deffi/noteeds
def adjust_size(rect: QRect, dw: int, dh: int,
                layout_direction: Qt.LayoutDirection) -> None:
    if layout_direction == Qt.RightToLeft:
        rect.adjust(-dw, -dh, 0, 0)
    else:
        rect.adjust(0, 0, dw, dh)