def paintEvent(self, e): # call the base implementation to paint normal interface QWidget.paintEvent(self, e); draw = QPainter(); draw.begin(self) h = self.height() - 1 diff = (self._higher - self._lower) * self.scale try: self._step = float(self.width()) / float(diff) except ZeroDivisionError: self._step = 0 x_start = (self._minVal - self._lower) * self._step * self.scale x_end = (self._maxVal - self._lower) * self._step * self.scale draw.setOpacity(1.0) draw.setBrush(QtCore.Qt.NoBrush) draw.setPen(QColor(200, 200, 255)) for i in range( int(self.width()/5), int(self.width()-self.width()/5) + 1, int(self.width()/5) ): draw.drawLine(i, 0, i, h) draw.setBrush(QColor(238, 238, 238)) draw.setPen(QColor(238, 238, 238)) draw.drawRoundedRect(0, 2, self.width(), h - 4, 3, 3) draw.setBrush(QColor(33, 133, 208)) draw.setPen(QColor(33, 133, 208)) draw.drawRoundedRect(int(round(x_start)), 2, int(round(x_end - x_start)), h - 4, 3, 3) # draw.setOpacity(1.0) draw.setFont(QFont('Decorative', 8)) draw.setPen(QColor(80, 80, 80)) str(self._maxVal) if self._use_float else str(int(round(self._maxVal))) boundtext = draw.boundingRect(QtCore.QRectF(), str(self._higher) if self._use_float else str(int(round(self._higher)))) draw.drawText(self.width() - boundtext.width(), 14, str(self._higher) if self._use_float else str(int(round(self._higher)))) draw.drawText(0, 14, str(self._lower) if self._use_float else str(int(round(self._lower)))) draw.setPen(QColor(255, 255, 255)) boundtext = draw.boundingRect(QtCore.QRectF(), str(self._minVal) if self._use_float else str(int(round(self._minVal)))) draw.drawText(x_start + 2, 14, str(self._minVal) if self._use_float else str(int(round(self._minVal)))) boundtext = draw.boundingRect(QtCore.QRectF(), str(self._maxVal) if self._use_float else str(int(round(self._maxVal)))) draw.drawText(x_end - boundtext.width(), 14, str(self._maxVal) if self._use_float else str(int(round(self._maxVal)))) draw.end()
def paintEvent(self, event): if self.__isTransparencySupported: opt = QStyleOption() opt.initFrom(self) rect = opt.rect p = QPainter(self) p.setRenderHint(QPainter.Antialiasing, True) p.setBrush(opt.palette.brush(QPalette.Window)) p.setPen(Qt.NoPen) p.drawRoundedRect(rect, self.__radius, self.__radius) p.end() else: StyledWidget_paintEvent(self, event)
def __updateMask(self): opt = QStyleOption() opt.initFrom(self) rect = opt.rect size = rect.size() mask = QBitmap(size) p = QPainter(mask) p.setRenderHint(QPainter.Antialiasing) p.setBrush(Qt.black) p.setPen(Qt.NoPen) p.drawRoundedRect(rect, self.__radius, self.__radius) p.end() self.setMask(mask)
def paintEvent(self, event): super().paintEvent(event) p = QPainter(self) p.setRenderHint(QPainter.Antialiasing) p.setBrush(self.indicator_color) p.save() p.setPen(Qt.NoPen) fm = QFontMetrics(self.font()) width = self.rect().width() height = fm.height() + 6 rect = QRectF(0, 0, width, height) p.drawRoundedRect(rect, 5, 5) p.restore() textstart = (width - fm.width(self.indicator_text)) / 2 p.drawText(textstart, height / 2 + 5, self.indicator_text)
def picture_this_level(): # Create a QPicture drawing the contribution from this # level only. This is all regions where the contingency is # not empty and does not have a computed sub-contingency # (i.e. the node does not have a child in that cell). pic = QPicture() painter = QPainter(pic) ctng = node.contingencies colors = create_image(ctng, palette, scale=scale) x, y, w, h = node.brect N, M = ctng.shape[:2] # Nonzero contingency mask any_mask = Node_mask(node) if node.is_leaf: skip = itertools.repeat(False) else: # Skip all None children they were already painted. skip = (ch is not None for ch in node.children.flat) painter.save() painter.translate(x, y) painter.scale(w / node.nbins, h / node.nbins) indices = itertools.product(range(N), range(M)) for (i, j), skip, any_ in zip(indices, skip, any_mask.flat): if not skip and any_: painter.setBrush(QColor(*colors[i, j])) if shape == Rect: painter.drawRect(i, j, 1, 1) elif shape == Circle: painter.drawEllipse(i, j, 1, 1) elif shape == RoundRect: painter.drawRoundedRect(i, j, 1, 1, 25.0, 25.0, Qt.RelativeSize) painter.restore() painter.end() return pic