def paintEvent(self, event): painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) pen = painter.pen() fontscale = float(self._scale) painter.setFont(scaledFont(self.valueFont, 0.9)) h = self.props['height'] * fontscale w = self.props['width'] * fontscale elwidth = w / 20. elheight = h / 3 pol_bits = self.props['polarizer'] is_in = int(self._curval[0] << pol_bits | self._curval[7]) is_out = int(self._curval[1] << pol_bits | self._curval[8]) x = elwidth y = 2.5 * fontscale for i in range(18): painter.setPen(QPen(_black.color())) painter.setBrush(_grey) painter.drawRect(x, y, elwidth - 2, elheight) painter.setBrush(_blue) if is_in & (1 << (17 - i)): ely = 3 elif is_out & (1 << (17 - i)): ely = 2 + elheight / 2 else: ely = 2 + elheight / 4 painter.drawRect(x + 3, y + ely, elwidth - 8, elheight / 3) if i >= 18 - pol_bits: painter.setPen(QPen(_white.color())) painter.drawText(x + 3, y + ely - 2, elwidth - 8, elheight / 3 + 2, Qt.AlignHCenter, 'POL') painter.setPen(QPen(_black.color())) painter.drawText(x, 3, elwidth, 2 * fontscale, Qt.AlignRight | Qt.AlignTop, str(19 - i)) x += elwidth painter.fillRect(0, y + elheight / 3 - 5, w, 3, _yellow) painter.setPen(pen) x = elwidth + 1 y += elheight + 4 slhw = 1.6 * elwidth for i, slitpos in enumerate([20, 14, 8, 4, 2]): slitw, slith = self._curval[2 + i] xmiddle = x + ((20 - slitpos) * elwidth) painter.drawLine(xmiddle, y, xmiddle, y + 15) painter.setBrush(_white) painter.drawRect(xmiddle - 0.5 * slhw, y + 15, slhw, slhw) painter.setBrush(collstatusbrush[self._curstatus[2 + i]]) w = (50 - slitw) * slhw / 100 h = (50 - slith) * slhw / 100 painter.drawRect(xmiddle - 0.5 * slhw + w, y + 15 + h, slhw - 2 * w, slhw - 2 * h) painter.drawText(xmiddle - 0.8 * elwidth, y + 15, slhw, slhw, Qt.AlignCenter, '%.1f\n%.1f' % (slitw, slith))
def paintEvent(self, event): painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) h = self._scale * 2.5 * self.props['height'] w = self._scale * self.props['width'] # cache pen pen = painter.pen() if self.props['name']: painter.setFont(self.font()) if self._curstatus != OK: painter.fillRect(0, 0, w, self._scale * 2.5, statusbrush[self._curstatus]) if self._fixed: painter.setPen(QPen(_blue.color())) else: painter.setPen(QPen(_black.color())) painter.drawText(0, 0, w, self._scale * 2.5, Qt.AlignCenter, self.props['name']) painter.setPen(pen) yoff = self._scale * 2.5 else: yoff = 0 painter.setPen(QPen(_blue.color())) y = h * 0.5 + yoff painter.drawLine(0, y, w, y) painter.drawLine(0, y + 1, w, y + 1) painter.drawLine(0, y + 2, w, y + 2) # reset pen painter.setPen(pen) painter.setBrush(statusbrush[self._curstatus]) if self._curstr in self.props['options']: self.shift = self.props['options'].index(self._curstr) if self._curstr in self.props['disabled_options']: self.shift = len(self.props['options']) painter.setFont(self.valueFont) h0 = max(2 * self._scale, 2 * self._scale + 4) painter.setClipRect(0, yoff, w, h) for i, t in enumerate(self.props['options']): y = h * 0.5 + yoff + h0 * (self.shift - i - 0.45) b = statusbrush[self._curstatus] if t == self._curstr: painter.setBrush(b) else: painter.setBrush(_grey if b == statusbrush[OK] else b) painter.drawRect(5, y + 2, w - 10, h0 - 4) painter.drawText(5, y + 2, w - 10, h0 - 4, Qt.AlignCenter, t)
def lineNumberAreaPaintEvent(self, event): painter = QPainter(self.lineNumberArea) painter.fillRect(event.rect(), Qt.lightGray) block = self.firstVisibleBlock() blockNumber = block.blockNumber() top = int( self.blockBoundingGeometry(block).translated( self.contentOffset()).top()) bottom = top + int(self.blockBoundingRect(block).height()) while block.isValid() and top <= event.rect().bottom(): if block.isVisible() and bottom >= event.rect().top(): number = str(blockNumber + 1) painter.setPen(Qt.black) painter.drawText(0, top, self.lineNumberArea.width(), self.fontMetrics().height(), Qt.AlignRight, number) block = block.next() top = bottom bottom = top + int(self.blockBoundingRect(block).height()) blockNumber += 1