def paintEvent(self, pevent): """ Paint event handler. Reimplemented for drawing rule group frames. """ super(ParameterView, self).paintEvent(pevent) grid = self.grid() offset = grid.contentsMargins().left() / 2 for frame in self._frames: start_cell = grid.cellRect(frame.top(), frame.left()) finish_cell = QRect() for col in xrange(frame.right(), frame.left() - 1, -1): for row in xrange(frame.bottom(), frame.top() - 1, -1): finish_cell = grid.cellRect(row, col) if finish_cell.isValid(): break if finish_cell.isValid(): break rect = QRect(start_cell.topLeft(), finish_cell.bottomRight()) if rect.isValid(): rect.adjust(-offset, -offset, offset, offset) self._paintGroupBox(rect, frame.title \ if hasattr(frame, "title") else "")
def paint(self, painter, option, index): QStyledItemDelegate.paint(self, painter, option, index) hovering = index.data(HOVER_ROLE) is True painter.save() rect = option.rect is_current = index.data(Qt.FontRole) is not None if not hovering and is_current: qpp = QPainterPath() qpp.addRoundedRect(QRectF(rect), 6, 6) painter.fillPath(qpp, self.current_background) icon_rect = QRect(rect.left() + self.MARGIN, rect.top() + self.MARGIN, ICON_SIZE, ICON_SIZE) left = icon_rect.right() + 2 * self.MARGIN text_rect = QRect(left, icon_rect.top(), rect.width() - left + rect.left(), icon_rect.height()) mark = index.data(MARK_ROLE) if hovering or mark: text_rect.adjust(0, 0, -text_rect.height(), 0) text = index.data(DISPLAY_ROLE) or '' font = index.data(Qt.FontRole) if font: painter.setFont(font) text_flags = Qt.AlignVCenter | Qt.AlignLeft | Qt.TextSingleLine text = elided_text(text, font, text_rect.width(), 'right') if option.state & QStyle.State_Selected: painter.setPen(QPen(self.highlighted_text)) painter.drawText(text_rect, text_flags, text) if mark: hrect = QRect(text_rect.right(), text_rect.top(), text_rect.height(), text_rect.height()) painter.fillRect(hrect, QColor('#ffffaa')) painter.drawText(hrect, Qt.AlignCenter, mark) elif hovering: hrect = QRect(text_rect.right(), text_rect.top(), text_rect.height(), text_rect.height()) close_hover = index.data(CLOSE_HOVER_ROLE) is True if close_hover: pen = painter.pen() pen.setColor(QColor('red')) painter.setPen(pen) painter.drawText(hrect, Qt.AlignCenter, '✖ ') if index.data(LOADING_ROLE): if not self.errored_out: angle = index.data(ANGLE_ROLE) try: draw_snake_spinner(painter, icon_rect, angle, self.light, self.dark) except Exception: import traceback traceback.print_exc() self.errored_out = True else: icurl = index.data(URL_ROLE) if icurl == WELCOME_URL: icon = welcome_icon() elif icurl == DOWNLOADS_URL: icon = downloads_icon() else: icon = index.data(DECORATION_ROLE) icon.paint(painter, icon_rect) painter.restore()
def paintEvent(self, pevent): """ Paint event handler. Reimplemented for drawing rule group frames. """ super(ParameterItemHilighter, self).paintEvent(pevent) painter = QPainter(self) rect = QRect(0, 0, self.width(), self.height()) rect.adjust(1, 1, -1, -1) painter.setPen(Qt.red) painter.drawRect(rect)
def paintTab(self, painter, tabIndex): ''' @param: painter QPainter @param: tabIndex int ''' if not self.validIndex(tabIndex): print('Warning: invalid index %s' % tabIndex) return painter.save() rect = self.tabRect(tabIndex) selected = (tabIndex == self._currentIndex) if selected: # background painter.save() grad = QLinearGradient(rect.topLeft(), rect.topRight()) grad.setColorAt(0, QColor(255, 255, 255, 140)) grad.setColorAt(1, QColor(255, 255, 255, 210)) painter.fillRect(rect.adjusted(0, 0, 0, -1), grad) painter.restore() # shadows painter.setPen(QColor(0, 0, 0, 110)) painter.drawLine(rect.topLeft() + QPoint(1, -1), rect.topRight() - QPoint(0, 1)) painter.drawLine(rect.bottomLeft(), rect.bottomRight()) painter.setPen(QColor(0, 0, 0, 40)) painter.drawLine(rect.topLeft(), rect.bottomLeft()) # highlights painter.setPen(QColor(255, 255, 255, 50)) painter.drawLine(rect.topLeft() + QPoint(0, -2), rect.topRight() - QPoint(0, 2)) painter.drawLine(rect.bottomLeft() + QPoint(0, 1), rect.bottomRight() + QPoint(0, 1)) painter.setPen(QColor(255, 255, 255, 40)) painter.drawLine(rect.topLeft() + QPoint(0, 0), rect.topRight()) painter.drawLine(rect.topRight() + QPoint(0, 1), rect.bottomRight() - QPoint(0, 1)) painter.drawLine(rect.bottomLeft() + QPoint(0, -1), rect.bottomRight() - QPoint(0, 1)) # QString tabText(painter->fontMetrics().elidedText(this->tabText(tabIndex), Qt::ElideMiddle, width())); tabTextRect = self.tabRect(tabIndex) tabIconRect = QRect(tabTextRect) tabIconRect.adjust(+4, +4, -4, -4) tabTextRect.translate(0, -2) boldFont = QFont(painter.font()) boldFont.setPointSizeF(styleHelper.sidebarFontSize()) boldFont.setBold(True) painter.setFont(boldFont) painter.setPen(selected and QColor(255, 255, 255, 160) or QColor(0, 0, 0, 110)) # int textFlags = Qt::AlignCenter | Qt::AlignBottom # painter->drawText(tabTextRect, textFlags, tabText) painter.setPen(selected and QColor(60, 60, 60) or styleHelper.panelTextColor()) if not const.OS_MACOS: if not selected: painter.save() fader = int(self._tabs[tabIndex].fader) grad = QLinearGradient(rect.topLeft(), rect.topRight()) grad.setColorAt(0, Qt.transparent) grad.setColorAt(0.5, QColor(255, 255, 255, fader)) grad.setColorAt(1, Qt.transparent) # painter.fillRect(rect, grad) # painter.setPen(QPen(grad, 1.0)) painter.fillRect(rect, QColor(255, 255, 255, fader)) painter.setPen(QPen(QColor(255, 255, 255, fader), 1.0)) painter.drawLine(rect.topLeft(), rect.topRight()) painter.drawLine(rect.bottomLeft(), rect.bottomRight()) painter.restore() # const int textHeight = painter->fontMetrics().height(); tabIconRect.adjust(0, 6, 0, -6) if selected: iconMode = QIcon.Selected else: iconMode = QIcon.Normal styleHelper.drawIconWithShadow(self.tabIcon(tabIndex), tabIconRect, painter, iconMode) painter.translate(0, -1) # painter->drawText(tabTextRect, textFlags, tabText) painter.restore()