def paintEvent(self, event): """Display a translucent rounded rectangle.""" roundness = 10 rect = self.rect() bgcolor = self.palette().color(QPalette.Background) alpha_bgcolor = QColor(50, 50, 50, 150) # alpha_bgcolor = QColor(bgcolor.red(), bgcolor.green(), # bgcolor.blue(), 150) painter = QPainter() painter.begin(self) painter.save() painter.setRenderHint(QPainter.Antialiasing) painter.setPen(Qt.red) rounded_rect = QPainterPath() rounded_rect.addRoundRect(1, 1, rect.width() - 2, rect.height() - 2, roundness, roundness) painter.setClipPath(rounded_rect) self.setMask(painter.clipRegion()) painter.setOpacity(1.0) painter.fillPath(rounded_rect, QBrush(alpha_bgcolor)) painter.restore() painter.end()
def paintEvent(self, event): painter = QPainter(self) # Фон painter_path = QPainterPath() painter_path.addRect(0, 0, self.width() - 1, self.height() - 1) painter.fillPath(painter_path, QBrush(QImage(':/main/background.png'))) if self.image: painter.drawText(10, 20, str(self.image.draw_scale)) painter.setTransform(QTransform().scale( self.image.draw_scale, self.image.draw_scale).translate(self.image.draw_offset.x(), self.image.draw_offset.y())) old_pen = painter.pen() new_pen = QPen() new_pen.setColor(QColor(0, 150, 0)) painter.setPen(new_pen) self.image.draw(painter) painter.setPen(old_pen)
def paintEvent(self, event): painter = QPainter(self) # Фон painter_path = QPainterPath() painter_path.addRect(0, 0, self.width() - 1, self.height() - 1) painter.fillPath(painter_path, QBrush(QImage(':/main/background.png'))) if self.image: painter.drawText(10, 20, str(self.image.draw_scale)) painter.setTransform(QTransform(). scale(self.image.draw_scale, self.image.draw_scale). translate(self.image.draw_offset.x(), self.image.draw_offset.y())) old_pen = painter.pen() new_pen = QPen() new_pen.setColor(QColor(0, 150, 0)) painter.setPen(new_pen) self.image.draw(painter) painter.setPen(old_pen)
def paintEvent(self, event): """Display a translucent rounded rectangle.""" roundness = 10 rect = self.rect() bgcolor = self.palette().color(QPalette.Background) alpha_bgcolor = QColor(50, 50, 50, 150) #alpha_bgcolor = QColor(bgcolor.red(), bgcolor.green(), # bgcolor.blue(), 150) painter = QPainter() painter.begin(self) painter.save() painter.setRenderHint(QPainter.Antialiasing) painter.setPen(Qt.red) rounded_rect = QPainterPath() rounded_rect.addRoundRect(1, 1, rect.width() - 2, rect.height() - 2, roundness, roundness) painter.setClipPath(rounded_rect) self.setMask(painter.clipRegion()) painter.setOpacity(1.0) painter.fillPath(rounded_rect, QBrush(alpha_bgcolor)) painter.restore() painter.end()
def paintEvent(self, event): # print self.height() s = (self.target_angle - self.angle) * 0.09 self.angle += s if math.fabs(self.angle - self.target_angle) < 0.001: self.angle = self.target_angle self.timer.stop() painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) qp = QPainterPath() width = min(self.height(), (self.width() / 2)) height = self.height() # center x = self.width() / 2 big_radius = 1000 y = big_radius + 10 small_radius = big_radius - 15 ac = math.atan(float(self.width()) / 2.0 / float(big_radius)) / math.pi * 180.0 * 0.95 qp.arcMoveTo(x - big_radius, y - big_radius, 2 * big_radius, 2 * big_radius, 90 - ac) qp.arcTo(x - big_radius, y - big_radius, 2 * big_radius, 2 * big_radius, 90 - ac, 2 * ac) qp.arcTo(x - small_radius, y - small_radius, 2 * small_radius, 2 * small_radius, 90 + ac, -2 * ac) qp.arcTo(x - big_radius, y - big_radius, 2 * big_radius, 2 * big_radius, 90 - ac, 0) # qp.lineTo(x+big_radius,y) grange = ac * 2.0 / 360.0 # Centered on 0, starting at angle 90-ac, counterclockwise self.gradient = QConicalGradient(0, 0, 90 - ac - 1) if self.gradient_type == 1: self.gradient.setColorAt(0, Qt.GlobalColor.red) self.gradient.setColorAt(0.1, Qt.GlobalColor.yellow) self.gradient.setColorAt(0.2, Qt.GlobalColor.green) self.gradient.setColorAt(0.5, Qt.GlobalColor.green) self.gradient.setColorAt(0.5, Qt.GlobalColor.green) elif self.gradient_type == 2: self.gradient.setColorAt(0, Qt.GlobalColor.green) self.gradient.setColorAt(0.6 * grange, Qt.GlobalColor.yellow) self.gradient.setColorAt(1 * grange, Qt.GlobalColor.red) elif self.gradient_type == 3: self.gradient.setColorAt(0 * grange, Qt.GlobalColor.red) self.gradient.setColorAt(0.05 * grange, Qt.GlobalColor.yellow) self.gradient.setColorAt(0.1 * grange, Qt.GlobalColor.green) self.gradient.setColorAt(0.4 * grange, Qt.GlobalColor.green) self.gradient.setColorAt(0.45 * grange, Qt.GlobalColor.yellow) self.gradient.setColorAt(0.5 * grange, Qt.GlobalColor.red) self.gradient.setCenter(x, y) painter.fillPath(qp, QBrush(self.gradient)) pen = QPen() pen.setColor(Qt.GlobalColor.black) pen.setWidth(max(1, int(1 * self.width() / 300))) painter.setPen(pen) painter.drawPath(qp) qp = QPainterPath() #qp.moveTo(0,0) #qp.lineTo(x,y) #qp.lineTo(self.width(),0) angle = 0 ac = math.atan(float(self.width()) / 2.0 / float(big_radius)) * 0.95 if self.direction == self.UNIDIRECTIONAL: angle = math.pi / 2 + ac * (1 - 2 * self.angle) elif self.direction == self.BIDIRECTIONAL: angle = math.pi / 2 - self.angle * ac length = big_radius + 10 short_length = small_radius - 10 qp.moveTo(x + math.cos(angle) * short_length, y - math.sin(angle) * short_length) qp.lineTo(x + math.cos(angle) * length, y - math.sin(angle) * length) pen = QPen() pen.setCapStyle(Qt.RoundCap) pen.setColor(Qt.GlobalColor.black) pen.setWidth(max(3, int(3 * width / 300))) painter.setPen(pen) painter.drawPath(qp) qp = QPainterPath() delta = self.width() * 0.025 # print "{}-{} {} c:{}".format(x,y,delta,math.cos(angle)) qp.moveTo(x + delta + math.cos(angle) * short_length, y + delta - math.sin(angle) * short_length) qp.lineTo(x + delta + math.cos(angle) * length, y + delta - math.sin(angle) * length) pen = QPen() pen.setCapStyle(Qt.RoundCap) pen.setColor(QColor.fromRgbF(0, 0, 0, 0.3)) pen.setWidth(max(3, int(3 * width / 300))) painter.setPen(pen) painter.drawPath(qp) qp = QPainterPath() qp.addRect(0, 0, self.width(), self.height()) painter.drawPath(qp)
def paintEvent(self, pe): p = QPainter(self) p.setRenderHint(QPainter.Antialiasing) pen = QPen() pen.setColor(Qt.GlobalColor.black) pen.setWidth(2) pen.setJoinStyle(Qt.MiterJoin) p.setPen(pen) h = self.associated_label.sizeHint().height() w = h pw = pen.width() b = self.italic_block(pw+0,w,h) p.translate(self.shadow_size,self.shadow_size) p.fillPath(b, QBrush(Qt.gray)) p.translate(-self.shadow_size,-self.shadow_size) p.fillPath(b, QBrush(self.Colors[self.step])) p.drawPath(b) b = self.italic_block(pw+w*1.25,w*0.75,h) p.translate(self.shadow_size,self.shadow_size) p.fillPath(b, QBrush(Qt.gray)) p.translate(-self.shadow_size,-self.shadow_size) p.fillPath(b, QBrush(self.Colors[self.step+1])) p.drawPath(b) b = self.italic_block(pw+w*2.25,w*0.4,h) p.translate(self.shadow_size,self.shadow_size) p.fillPath(b, QBrush(Qt.gray)) p.translate(-self.shadow_size,-self.shadow_size) p.fillPath(b, QBrush(self.Colors[self.step+2])) p.drawPath(b)