def paintEvent(self, event): painter = QtGui.QPainter(self) painter.setPen(QtCore.Qt.NoPen) painter.setBrush( QtGui.QBrush( QtGui.QColor(self.text_color.red(), self.text_color.green(), self.text_color.blue(), 20))) painter.drawRoundedRect(0, 0, self.width(), self.height(), 5, 5) super(_BaseNoteWidget, self).paintEvent(event)
def paint(self, painter, option, widget): bbox = self.boundingRect() if self.isSelected(): self.set_highlight() pen = QtGui.QPen(self.border_color) pen.setWidth(2) painter.setPen(pen) painter.setBrush(QtGui.QBrush(self.fill_color)) painter.drawRoundedRect(self.x, self.y, bbox.width(), self.h, self.roundness, self.roundness) else: painter.setPen(QtGui.QPen(QtCore.Qt.NoPen)) painter.setBrush(QtGui.QBrush(self.base_color)) # painter.setBrush(QtGui.QBrush(self.fill_color)) # painter.drawRoundedRect(self.x, # self.y, # bbox.width(), # self.h, # self.roundness, # self.roundness) # # painter.setBrush(QtGui.QBrush(self.fill_color)) # painter.drawRect(self.x, # self.y + self.roundness, # bbox.width(), # self.h - 50 - self.roundness) # painter.drawRoundedRect(self.x, # self.y, # bbox.width(), # self.h - 50, # self.roundness, # self.roundness) painter.setBrush(QtGui.QBrush(self.fill_color)) painter.drawRoundedRect(self.x, self.y, bbox.width(), self.h, self.roundness, self.roundness) painter.setBrush(QtGui.QBrush(self.base_color)) painter.drawRect(self.x, self.y + 30, bbox.width(), self.h - 30 - self.roundness) painter.drawRoundedRect(self.x, self.y + 30, bbox.width(), self.h - 30, self.roundness, self.roundness)
def paint(self, painter, option, widget): """Draw the Tag's shape and label.""" bbox = self.boundingRect() if self.shape is not None: painter.setPen(QtGui.QPen(QtCore.Qt.NoPen)) painter.setBrush(QtGui.QBrush(self.fillColor)) # Draw a filled rectangle. if self.shape == 1: roundness = 3 painter.drawRoundedRect(bbox, roundness, roundness) # Ellipse if self.shape == 2: painter.drawEllipse(bbox) # Triangle0 if self.shape == 3: points, rects = get_shapes_of_triangle(self.w, roundness=2, direction=0) painter.drawPolygon(QtGui.QPolygonF(points)) for rect in rects: painter.drawEllipse(rect) # Triangle2 if self.shape == 4: points, rects = get_shapes_of_triangle(self.w, roundness=2, direction=2) painter.drawPolygon(QtGui.QPolygonF(points)) for rect in rects: painter.drawEllipse(rect) if self.text is not None: painter.setPen(QtGui.QPen(self.textColor)) font = painter.font() fm = QtGui.QFontMetrics(font) w = fm.boundingRect(self.text).width() + 10 h = fm.boundingRect(self.text).height() rect = QtCore.QRectF(0 - (w - bbox.width()) / 2.0, 0 - (h - bbox.height()) / 2.0, w, h) painter.drawText(rect, QtCore.Qt.AlignCenter, self.text)
def paint(self, painter, option, widget): """Draw the Knob's shape and label.""" bbox = self.boundingRect() # Draw a filled rectangle. # painter.setPen(QtGui.QPen(QtCore.Qt.NoPen)) pen = QtGui.QPen(QtGui.QColor(200, 200, 250)) pen.setWidth(1) painter.setPen(pen) painter.setBrush(QtGui.QBrush(self.fillColor)) # painter.drawRect(bbox) painter.drawEllipse(bbox) # Draw a text label next to it. Position depends on the flow. if self.flow == FLOW_LEFT_TO_RIGHT: x = bbox.right() + self.margin elif self.flow == FLOW_RIGHT_TO_LEFT: x = bbox.left() - self.margin else: raise Exception("Flow not recognized: {0}".format(self.flow)) y = bbox.bottom() self.setZValue(10)
def drawBackground(self, painter, rect): painter.setBrush(QtGui.QBrush(self.fillColor)) painter.setPen(QtGui.QPen(self.lineColor)) painter.drawRect(rect) lines = [] scale = max(int(1 / self.current_zoom / 2), 1) line_w = 200 * scale line_h = 80 * scale point1 = self.mapToScene(QtCore.QPoint(0, 0)) point2 = self.mapToScene( QtCore.QPoint(self.viewport().width(), self.viewport().height())) # for i in range(int(point1.y() / line_h), int(self.scene().height() / line_h)): for i in range(int(point1.y() / line_h), int(point2.y() / line_h)): lines.append( QtCore.QLineF( QtCore.QPoint(rect.x(), i * line_h), QtCore.QPoint(rect.x() + rect.width(), i * line_h))) # for i in range(int(self.scene().sceneRect().x()), int(self.scene().width() / line_w)): for i in range(int(point1.x() / line_w), int(point2.x() / line_w)): lines.append( QtCore.QLineF( QtCore.QPoint(i * line_w, rect.y()), QtCore.QPoint(i * line_w, rect.y() + rect.height()))) painter.drawLines(lines) painter.setPen(QtGui.QPen(QtGui.QColor(80, 80, 60, 50))) painter.drawLine( QtCore.QLineF(QtCore.QPoint(rect.x(), 0), QtCore.QPoint(rect.x() + rect.width(), 0))) painter.drawLine( QtCore.QLineF(QtCore.QPoint(0, rect.y()), QtCore.QPoint(0, rect.y() + rect.height())))