def __initSVGFile(self, filename): generator = QtSvg.QSvgGenerator() generator.setFileName(os.path.join(self.__startDir, filename)) generator.setSize(QtCore.QSize(self.__width, self.__height)) generator.setViewBox(QtCore.QRect(0, 0, self.__width, self.__height)) painter = QtGui.QPainter(generator) painter.setClipRect(QtCore.QRect(0, 0, self.__width, self.__height)) return generator, painter
def update_tooltip(self, gap=5): nodes = [node() for node in self.children] n_side = len(nodes) if n_side > 3: n_side = max(1, int(n_side**0.5)) x = 0 y = 0 h_max = 0 n = 0 x_max, y_max = 0, 0 positions = [] for node in nodes: positions.append([x + gap, y + gap]) w, h = node._rect.width() + gap, node._rect.height() + gap h_max = max(h_max, h) x += w n += 1 if n > n_side: x = 0 y += h_max h_max = 0 n = 0 x_max = max(x_max, x + w) y_max = max(y_max, y + h) if n_side == len(nodes): x_max -= w scale = SCALE_TOOLTIP / SCALE_DRAWINGS buffer = QtCore.QBuffer() buffer.open(QtCore.QIODevice.WriteOnly) gen = QtSvg.QSvgGenerator() gen.setOutputDevice(buffer) painter = QtGui.QPainter(gen) painter.scale(scale, scale) painter.setPen(QtGui.QPen(QtCore.Qt.white, 0)) painter.setBrush(QtGui.QBrush(QtCore.Qt.white)) rect = QtCore.QRectF(0, 0, x_max, y_max) painter.drawRect(rect) painter.setPen(QtGui.QPen(QtCore.Qt.black, 0.5)) for i in range(len(nodes)): x, y = positions[i] painter.drawPicture(x, y, nodes[i].picture) painter.drawText(rect, QtCore.Qt.AlignCenter | QtCore.Qt.AlignBottom, self.label) painter.end() self.tool_tip = "<img src=\"data:image/png;base64,%s\">" % (bytes( buffer.data().toBase64()).decode())
def update_tooltip(self): buffer = QtCore.QBuffer() buffer.open(QtCore.QIODevice.WriteOnly) scale = SCALE_TOOLTIP / SCALE_DRAWINGS gen = QtSvg.QSvgGenerator() gen.setOutputDevice(buffer) painter = QtGui.QPainter(gen) painter.scale(scale, scale) rect = self._rect.marginsAdded(QtCore.QMargins(10, 10, 10, 10)) rect = QtCore.QRectF(rect.x(), rect.y(), rect.width() * 0.8, rect.height()) painter.setPen(QtGui.QPen(QtCore.Qt.white, 0)) painter.setBrush(QtGui.QBrush(QtCore.Qt.white)) painter.drawRect(rect) painter.setPen(QtGui.QPen(QtCore.Qt.black, 0.5)) painter.drawPicture(0, 0, self.picture) painter.drawText(rect, QtCore.Qt.AlignCenter | QtCore.Qt.AlignBottom, self.label) painter.end() self.tool_tip = "<img src=\"data:image/png;base64,%s\">" % (bytes( buffer.data().toBase64()).decode())