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 drawControl(self, element, option, painter, widget): ''' @param: element ControlElement @param: option QStyleOption @param: painter QPainter @param: widget QWidget ''' v_opt = option if element != self.CE_TabBarTab or not isinstance( v_opt, QStyleOptionTab): QProxyStyle.drawControl(element, option, painter, widget) return rect = v_opt.rect selected = v_opt.state & self.State_Selected vertical_tabs = v_opt.shape == QTabBar.RoundedWest text = v_opt.text if selected: # background painter.save() grad = QLinearGradient(rect.topLeft(), rect.topRight()) grad.setColorAt(0, QColor(255, 255, 255, 140)) grad.setColorAt(0, 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)) m = QTransform() if vertical_tabs: m = QTransform.fromTranslate(rect.left(), rect.bottom()) m.rotate(-90) else: m = QTransform.fromTranslate(rect.left(), rect.top()) draw_rect = QRect(QPoint(0, 0), m.mapRect(rect).size()) painter.save() painter.setTransform(m) icon_rect = QRect(QPoint(8, 0), v_opt.iconSize) text_rect = QRect(icon_rect.topRight() + QPoint(4, 0), draw_rect.size()) text_rect.setRight(draw_rect.width()) icon_rect.translate(0, (draw_rect.height() - icon_rect.height()) / 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)) textFlags = Qt.AlignHCenter | Qt.AlignVCenter painter.drawText(text_rect, textFlags, text) painter.setPen(selected and QColor(60, 60, 60) or styleHelper.panelTextColor()) if widget: fader_key = 'tab_' + text + '_fader' animation_key = 'tab_' + text + '_animation' tab_hover = widget.property('tab_hover') # int fader = widget.property(fader_key) # QPropertyAnimation animation = widget.property(animation_key) if not animation: mut_widget = widget fader = 0 mut_widget.setProperty(fader_key, fader) animation = QPropertyAnimation(mut_widget, fader_key, mut_widget) animation.valueChanged.connect(mut_widget.update) mut_widget.setProperty(animation_key, animation) if text == tab_hover: if animation.state( ) != QAbstractAnimation.Running and fader != 40: animation.stop() animation.setDuration(80) animation.setEndValue(40) animation.start() else: if animation.state( ) != QAbstractAnimation.Running and fader != 0: animation.stop() animation.setDuration(160) animation.setEndValue(0) animation.start() if not selected: painter.save() painter.fillRect(draw_rect, QColor(255, 255, 255, fader)) painter.setPen(QPen(QColor(255, 255, 255, fader), 1.0)) painter.drawLine( draw_rect.topLeft(), vertical_tabs and draw_rect.bottomLeft() or draw_rect.topRight()) painter.drawLine( draw_rect.bottomRight(), vertical_tabs and draw_rect.topRight() or draw_rect.bottomLeft()) painter.restore() if selected: iconMode = QIcon.Selected else: iconMode = QIcon.Normal styleHelper.drawIconWithShadow(v_opt.icon, icon_rect, painter, iconMode) painter.drawText(text_rect.translated(0, -1), textFlags, text) painter.restore()