Ejemplo n.º 1
0
 def paintEvent(self, _):
     option = QStyleOptionButton()
     self.initStyleOption(option)
     painter = QStylePainter(self)
     if self._rotateAnimationStarted:
         option.text = ""
     painter.drawControl(QStyle.CE_PushButton, option)
     if not self._rotateAnimationStarted:
         return
     painter.save()
     font = self.font()
     font.setPointSize(self.fontSize)
     font.setFamily("FontAwesome")
     painter.setFont(font)
     # 变换坐标为正中间
     painter.translate(self.rect().center())
     # 旋转90度
     painter.rotate(self._rotateAnimation.currentValue() * 30)
     fm = self.fontMetrics()
     # 在变换坐标后的正中间画文字
     w = fm.width(self.LoadingText)
     h = fm.height()
     painter.drawText(QRectF(0 - w * 2, 0 - h, w * 2 * 2, h * 2),
                      Qt.AlignCenter, self.LoadingText)
     painter.restore()
Ejemplo n.º 2
0
    def paintEvent(self, event):
        """绘制事件"""
        text = self.text()
        option = QStyleOptionButton()
        self.initStyleOption(option)
        option.text = ''  # 不绘制文字
        painter = QStylePainter(self)
        painter.setRenderHint(QStylePainter.Antialiasing)
        painter.setRenderHint(QStylePainter.HighQualityAntialiasing)
        painter.setRenderHint(QStylePainter.SmoothPixmapTransform)
        painter.drawControl(QStyle.CE_PushButton, option)
        # 变换坐标为正中间
        painter.translate(self.rect().center())
        painter.rotate(self._angle)  # 旋转

        # 绘制图片
        if self._pixmap and not self._pixmap.isNull():
            w = self.width()
            h = self.height()
            pos = QPointF(-self._pixmap.width() / 2,
                          -self._pixmap.height() / 2)
            painter.drawPixmap(pos, self._pixmap)
        elif text:
            # 在变换坐标后的正中间画文字
            fm = self.fontMetrics()
            w = fm.width(text)
            h = fm.height()
            rect = QRectF(0 - w * 2, 0 - h, w * 2 * 2, h * 2)
            painter.drawText(rect, Qt.AlignCenter, text)
        else:
            super(RotateButton, self).paintEvent(event)
Ejemplo n.º 3
0
 def paintEvent(self, event: QPaintEvent) -> None:
     painter = QStylePainter(self)
     opt = QStyleOptionSlider()
     self.initStyleOption(opt)
     font = painter.font()
     font.setPixelSize(10)
     painter.setFont(font)
     if self.tickPosition() != QSlider.NoTicks:
         x = 8
         for i in range(self.minimum(), self.width(), 8):
             if i % 5 == 0:
                 h = 18
                 w = 1
                 z = 13
             else:
                 h = 8
                 w = 1
                 z = 23
             tickcolor = '#8F8F8F' if self.theme == 'dark' else '#444'
             pen = QPen(QColor(tickcolor))
             pen.setWidthF(w)
             painter.setPen(pen)
             if self.tickPosition() in (QSlider.TicksBothSides,
                                        QSlider.TicksAbove):
                 y = self.rect().top() + z
                 painter.drawLine(x, y, x, y + h)
             if self.tickPosition() in (QSlider.TicksBothSides,
                                        QSlider.TicksBelow):
                 y = self.rect().bottom() - z
                 painter.drawLine(x, y, x, y - h)
                 if self.parent.mediaAvailable and i % 15 == 0:
                     painter.setPen(Qt.white if self.theme ==
                                    'dark' else Qt.black)
                     timecode = QStyle.sliderValueFromPosition(
                         self.minimum(), self.maximum(), x - self.offset,
                         self.width() - (self.offset * 2))
                     timecode = self.parent.delta2QTime(timecode).toString(
                         self.parent.runtimeformat)
                     painter.drawText(x + 6, y + 6, timecode)
             if x + 30 > self.width():
                 break
             x += 15
     opt.subControls = QStyle.SC_SliderGroove
     painter.drawComplexControl(QStyle.CC_Slider, opt)
     for rect in self._regions:
         rect.setY(int((self.height() - self._regionHeight) / 2) - 8)
         rect.setHeight(self._regionHeight)
         if self._regions.index(rect) == self._regionSelected:
             brushcolor = QColor(150, 190, 78, 185)
         else:
             brushcolor = QColor(237, 242, 255, 185)
         painter.setBrush(brushcolor)
         painter.setPen(QColor(255, 255, 255, 170))
         painter.drawRect(rect)
     opt.subControls = QStyle.SC_SliderHandle
     painter.drawComplexControl(QStyle.CC_Slider, opt)
Ejemplo n.º 4
0
	def paintEvent(self, event):
		painter = QStylePainter(self)
		option = QStyleOptionTab()

		#painter.begin(self)
		for index in range(self.count()):
			self.initStyleOption(option, index)
			tabRect = self.tabRect(index)
			tabRect.moveLeft(10)
			painter.drawControl(QStyle.CE_TabBarTabShape, option)
			painter.drawText(tabRect, Qt.AlignVCenter | Qt.TextDontClip, self.tabText(index))
Ejemplo n.º 5
0
    def paintEvent(self, event):
        QFrame.paintEvent(self, event)
        text = QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate)
        logicalRect = QRectF(
            QPointF(0, 0),
            QSizeF(QFontMetrics(self.font()).size(Qt.TextSingleLine, text)))
        physicalRect, frameWidth = QRectF(self.rect()), self.frameWidth()
        physicalRect.adjust(frameWidth, frameWidth, -frameWidth, -frameWidth)
        scaleForWidth = physicalRect.width() / logicalRect.width()
        scaleForHeight = physicalRect.height() / logicalRect.height()
        logicalRect.moveTo(frameWidth / scaleForWidth,
                           frameWidth / scaleForHeight)

        painter = QStylePainter(self)
        painter.scale(scaleForWidth, scaleForHeight)
        painter.drawText(logicalRect, Qt.AlignCenter, text)
Ejemplo n.º 6
0
 def paintEvent(self, event):
     QLineEdit.paintEvent(self, event)
     if not self.text() and self.placeholderText() and \
             not self.hasFocus():
         p = QStylePainter(self)
         font = self.font()
         metrics = QFontMetrics(font)
         p.setFont(font)
         color = self.palette().color(QPalette.Mid)
         p.setPen(color)
         left, top, right, bottom = self.getTextMargins()
         contents = self.contentsRect()
         contents = contents.adjusted(left, top, -right, -bottom)
         text = metrics.elidedText(self.placeholderText(),
                                   Qt.ElideMiddle, contents.width())
         p.drawText(contents, Qt.AlignLeft | Qt.AlignVCenter, text)
Ejemplo n.º 7
0
 def paintEvent(self, event):
     '''绘制事件'''
     if not self._timer.isActive():
         return super(LinkButton, self).paintEvent(event)
     if self._direction in ("clockwise", "anticlockwise"):
         option = QStyleOptionButton()
         self.initStyleOption(option)
         option.text = ""  # 不让其绘制文字
         painter = QStylePainter(self)
         painter.drawControl(QStyle.CE_PushButton, option)
         # 变换坐标为正中间
         painter.translate(self.rect().center())
         painter.rotate(self._rotate)  # 旋转
         fm = self.fontMetrics()
         # 在变换坐标后的正中间画文字
         w = fm.width(self.text())
         h = fm.height()
         painter.drawText(QRectF(0 - w * 2, 0 - h, w * 2 * 2, h * 2),
                          Qt.AlignCenter, self.text())
         return
     super(LinkButton, self).paintEvent(event)
Ejemplo n.º 8
0
    def paintEvent(self, event):

        if not self.customStyle:
            return QGroupBox.paintEvent(self, event)

        p = QStylePainter(self)
        opt = QStyleOptionGroupBox()
        self.initStyleOption(opt)

        style = qApp.style()
        groupBox = opt

        # // Draw frame
        textRect = style.subControlRect(style.CC_GroupBox, opt, style.SC_GroupBoxLabel)
        checkBoxRect = style.subControlRect(style.CC_GroupBox, opt, style.SC_GroupBoxCheckBox)

        p.save()
        titleRect = style.subControlRect(style.CC_GroupBox, opt, style.SC_GroupBoxFrame)
        # r.setBottom(style.subControlRect(style.CC_GroupBox, opt, style.SC_GroupBoxContents).top())
        titleRect.setHeight(textRect.height())
        titleRect.moveTop(textRect.top())

        p.setBrush(QBrush(QColor(Qt.blue).lighter(190)))
        p.setPen(Qt.NoPen)
        p.drawRoundedRect(titleRect, 10, 10)
        p.restore()

        if groupBox.subControls & QStyle.SC_GroupBoxFrame:
            frame = QStyleOptionFrame()
            # frame.operator=(groupBox)
            frame.state = groupBox.state
            frame.features = groupBox.features
            frame.lineWidth = groupBox.lineWidth
            frame.midLineWidth = groupBox.midLineWidth
            frame.rect = style.subControlRect(style.CC_GroupBox, opt, style.SC_GroupBoxFrame)
            p.save()
            region = QRegion(groupBox.rect)
            if groupBox.text:
                ltr = groupBox.direction == Qt.LeftToRight
                finalRect = QRect()
                if groupBox.subControls & QStyle.SC_GroupBoxCheckBox:
                    finalRect = checkBoxRect.united(textRect)
                    finalRect.adjust(-4 if ltr else 0, 0, 0 if ltr else 4, 0)
                else:
                    finalRect = textRect

                region -= QRegion(finalRect)

            p.setClipRegion(region)
            style.drawPrimitive(style.PE_FrameGroupBox, frame, p)
            p.restore()

        # // Draw title
        if groupBox.subControls & QStyle.SC_GroupBoxLabel and groupBox.text:
            # textColor = QColor(groupBox.textColor)
            # if textColor.isValid():
            # p.setPen(textColor)
            # alignment = int(groupBox.textAlignment)
            # if not style.styleHint(QStyle.SH_UnderlineShortcut, opt):
            # alignment |= Qt.TextHideMnemonic

            # style.drawItemText(p, textRect,  Qt.TextShowMnemonic | Qt.AlignHCenter | alignment,
            # groupBox.palette, groupBox.state & style.State_Enabled, groupBox.text,
            # QPalette.NoRole if textColor.isValid() else QPalette.WindowText)

            p.save()
            topt = QTextOption(Qt.AlignHCenter | Qt.AlignVCenter)
            f = QFont()
            f.setBold(True)
            p.setFont(f)
            p.setPen(Qt.darkBlue)
            p.drawText(QRectF(titleRect), groupBox.text.replace("&", ""), topt)
            p.restore()

            if groupBox.state & style.State_HasFocus:
                fropt = QStyleOptionFocusRect()
                # fropt.operator=(groupBox)
                fropt.state = groupBox.state
                fropt.rect = textRect
                style.drawPrimitive(style.PE_FrameFocusRect, fropt, p)
Ejemplo n.º 9
0
    def paint(self, painter, option, index):
        dlg = index.model().data(index, Qt.DisplayRole)
        painter.setRenderHint(QPainter.Antialiasing)
        color = QColor(Qt.white)
        if option.state & QStyle.State_MouseOver:
            color = QColor(variables.HIGHLIGHT_COLOR)
            painter.setPen(QPen(color))
            painter.setBrush(QBrush(color))
            painter.drawRect(option.rect)
        painter.setPen(Qt.black)
        painter.setBrush(Qt.NoBrush)
        painter.drawLine(option.rect.bottomLeft(), option.rect.bottomRight())
        doc = QTextDocument(dlg.ip)
        doc.setDocumentMargin(0)
        doc.setDefaultFont(variables.font)
        textrect = QRect(option.rect)
        textrect = textrect.marginsRemoved(variables.IP_PADDING)
        textrect.setHeight(int(doc.size().height()))
        textrect.setWidth(int(doc.size().width()))
        offset = textrect.marginsAdded(variables.IP_PADDING).height()
        painter.setPen(Qt.black)
        painter.setFont(variables.font)
        painter.translate(textrect.x(), textrect.y())
        textrectf = QRectF(textrect)
        textrectf.moveTo(0, 0)
        doc.drawContents(painter, textrectf)
        painter.translate(-textrect.x(), -textrect.y())
        string = ""
        if dlg.user == variables.USER_ME:
            string += "You: "
        print(dlg.msg)
        string += dlg.msg
        fm = QFontMetrics(variables.font_small)
        textrect = QRect(option.rect)
        textrect.moveTop(textrect.y() + offset)
        textrect = textrect.marginsRemoved(variables.MSG_PADDING)
        textrect.setHeight(fm.lineSpacing())
        spainter = QStylePainter(painter.device(), QWidget())
        spainter.setRenderHint(QPainter.Antialiasing)
        if fm.horizontalAdvance(string) > textrect.width():
            fade = QLinearGradient(variables.MSG_PADDING.left() + textrect.width()* 0.9, 0, variables.MSG_PADDING.left() + textrect.width(), 0)
            fade.setSpread(QGradient.PadSpread)
            fade.setColorAt(0, Qt.darkGray)
            fade.setColorAt(1, color)
            pal = QPalette()
            pal.setBrush(QPalette.Text, QBrush(fade))
            spainter.setFont(variables.font_small)
            spainter.drawItemText(textrect, Qt.TextSingleLine, pal, True, string, QPalette.Text)
        else:
            spainter.setPen(Qt.darkGray)
            spainter.setFont(variables.font_small)
            spainter.drawText(textrect, Qt.TextSingleLine, string)
        p1 = textrect.bottomRight() + QPoint(36, -int(textrect.height() / 2))
        if dlg.status == variables.STATUS_UNREAD:
            spainter.setPen(Qt.NoPen)
            spainter.setBrush(QColor(variables.STATUS_COLOR))
            spainter.drawEllipse(p1, 7, 7)
        elif dlg.status == variables.STATUS_UNDELIVERED:
            pen = QPen(QColor(variables.STATUS_COLOR))
            pen.setWidth(2)
            spainter.setPen(pen)
            spainter.setBrush(Qt.NoBrush)
            spainter.drawEllipse(p1, 7, 7)
            spainter.drawLine(p1, p1 + QPoint(0, -5))
            spainter.drawLine(p1, p1 + QPoint(3, 0))
        elif dlg.status == variables.STATUS_NEW:
            pen = QPen(QColor(variables.STATUS_NEW_COLOR))
            pen.setWidth(5)
            spainter.setPen(pen)
            spainter.setBrush(Qt.NoBrush)
            spainter.drawEllipse(p1, 7, 7)
        #painter.translate(-textrect.x(), -textrect.y())

        '''doc = QTextDocument(str)