def __updateBackgroundPixmap(self, colors): """Updates the background image buffer based on the given colors @type colors: list<QBrush> @param colors: List of job background colors""" # Could draw it the max size and allow the resize on drawPixmap # that way the same buffer is always used assert threading.currentThread().getName() == "MainThread" buffer = QtGui.QPixmap(self.contentsRect().size()) buffer.fill(self.__baseColor) if colors: painter = QtGui.QPainter() painter.begin(buffer) try: rect = buffer.rect() # Number of jobs amount = len(colors) # Number of pixels per job ratio = float(rect.height())/amount for index, color in enumerate(colors): if color: painter.fillRect(rect.adjusted(0, ratio * index, 0, -(ratio * (amount - index - 1))), color) finally: painter.end() del painter self.__background = buffer
def _GenerateMissingSplash(self, app_name): image = QtGui.QImage(self.WIDTH, self.HEIGHT, QtGui.QImage.Format_RGB32) painter = QtGui.QPainter(image) painter.fillRect(image.rect(), QtGui.QBrush(QtGui.QColor(50, 50, 50))) font = QtGui.QFont("serif", min((self.WIDTH / len(app_name))*1.4, 250), 75, True) painter.setFont(font) painter.setPen(QtGui.QColor(80, 80, 80)) painter.drawText(30, image.height() - 60, app_name) return image
def paintEvent(self, event): QtWidgets.QWidget.paintEvent(self, event) #Skip this if too small, if splitter is all the way over painter = QtGui.QPainter(self) try: rect = self.contentsRect().adjusted(5, 5, -5, -5) painter.save() painter.fillRect(rect, QtGui.qApp.palette().color(QtGui.QPalette.Base)) if len(self.__history) > 1: stepWidth = rect.width() / float(len(self.__history) - 1) ratioHeight = (rect.height() - 2) / float(self.__max) # Box outline painter.setPen(QtCore.Qt.black) painter.drawRect(rect) painter.setPen(self.__color) points = QtGui.QPolygon(len(self.__history) + 2) # Bottom left #points.setPoint(0, rect.bottomLeft()) points.setPoint(0, rect.left() + 1, rect.bottom()) # All the data points num = 1 for i in range(len(self.__history)): points.setPoint( num, max(rect.x() + 1, rect.x() - 1 + stepWidth * i), rect.bottom() - ratioHeight * self.__history[i]) num += 1 # Bottom right points.setPoint(num, rect.bottomRight()) # Draw filled in painter.setBrush(self.__brush) painter.drawPolygon(points) # Draw subscription size line painter.setPen(QtCore.Qt.red) height = rect.bottom() - ratioHeight * self.__line painter.drawLine(rect.left() + 1, height, rect.right() - 1, height) finally: painter.restore() painter.end() del painter
def paintEvent(self, paintEvent): painter = QtGui.QPainter(self) self.__paintBackground(painter) # Put the baseline at 0, 0 painter.translate(0, self.height() / 2) painter.setFont(self.__labelFont) self.__paintSelection(painter) self.__paintTickmarks(painter) self.__paintLabels(painter) self.__paintFloatTime(painter) self.__paintStartTime(painter) self.__paintEndTime(painter)
def paintEvent(self, event): """Called when the widget is being redrawn @type event: QEvent @param event: The draw event""" assert threading.currentThread().getName() == "MainThread" self.__colorsLock.lockForWrite() try: if not self.__colors: return colors = self.__colors finally: self.__colorsLock.unlock() painter = QtGui.QPainter(self) painter.save() try: rect = self.contentsRect() # Number of pixels per job ratio = float(rect.height())/len(colors) # How far down the slider is shift = self.__sourceTree.verticalScrollBar().value() * ratio # Length not covered by the slider offPage = self.__sourceTree.verticalScrollBar().maximum() * ratio painter.drawPixmap(self.contentsRect(), self.__background, self.__background.rect()) # Draw the slider pen = QtGui.QPen(self.__colorInvalid) pen.setWidth(0) painter.setPen(pen) painter.setBrush(self.__brushPattern) painter.drawRect(rect.adjusted(2, shift, -2, -offPage + shift)) finally: painter.restore() painter.end() del painter
def _StampVersion(self, image, version): if version: painter = QtGui.QPainter(image) painter.setPen(self.COLOR_TEXT) flags = QtCore.Qt.AlignRight | QtCore.Qt.AlignTop painter.drawText(image.rect(), flags, "Version " + version)