Beispiel #1
0
    def renderItem(self, painter, widget, rect, fillBackground):
        """
        Render a legend entry into a given rectangle.

        :param QPainter painter: Painter
        :param QWidget widget: Widget representing a legend entry
        :param QRectF rect: Bounding rectangle
        :param bool fillBackground: When true, fill rect with the widget background
        """
        if fillBackground:
            if widget.autoFillBackground() or widget.testAttribute(
                    Qt.WA_StyledBackground):
                QwtPainter.drawBackground(painter, rect, widget)
        label = widget  # TODO: cast to QwtLegendLabel
        if label is not None:
            icon = label.data().icon()
            sz = icon.defaultSize()
            iconRect = QRectF(
                rect.x() + label.margin(),
                rect.center().y() - 0.5 * sz.height(),
                sz.width(),
                sz.height(),
            )
            icon.render(painter, iconRect, Qt.KeepAspectRatio)
            titleRect = QRectF(rect)
            titleRect.setX(iconRect.right() + 2 * label.spacing())
            painter.setFont(label.font())
            painter.setPen(label.palette().color(QPalette.Text))
            label.drawText(painter,
                           titleRect)  # TODO: cast label to QwtLegendLabel
Beispiel #2
0
 def layoutLegend(self, options, rect):
     """
     Find the geometry for the legend
     
     :param options: Options how to layout the legend
     :param QRectF rect: Rectangle where to place the legend
     :return: Geometry for the legend
     """
     hint = self.__data.layoutData.legend.hint
     if self.__data.legendPos in (QwtPlot.LeftLegend, QwtPlot.RightLegend):
         dim = min(
             [hint.width(),
              int(rect.width() * self.__data.legendRatio)])
         if not (options & self.IgnoreScrollbars):
             if hint.height() > rect.height():
                 dim += self.__data.layoutData.legend.hScrollExtent
     else:
         dim = min(
             [hint.height(),
              int(rect.height() * self.__data.legendRatio)])
         dim = max([dim, self.__data.layoutData.legend.vScrollExtent])
     legendRect = QRectF(rect)
     if self.__data.legendPos == QwtPlot.LeftLegend:
         legendRect.setWidth(dim)
     elif self.__data.legendPos == QwtPlot.RightLegend:
         legendRect.setX(rect.right() - dim)
         legendRect.setWidth(dim)
     elif self.__data.legendPos == QwtPlot.TopLegend:
         legendRect.setHeight(dim)
     elif self.__data.legendPos == QwtPlot.BottomLegend:
         legendRect.setY(rect.bottom() - dim)
         legendRect.setHeight(dim)
     return legendRect