[PyQt] QGraphicsScene/Item/View coordinates

Frédéric frederic.mantegazza at gbiloba.org
Tue Jan 27 10:56:59 GMT 2009


On dimanche 25 janvier 2009, Frédéric wrote:

> When I create all items representing the pictures, I use the following
> code:
>
> def paint(self, painter, options, widget):
>     ...
>     painter.fillRect(x, y, w, h, QtGui.QColor("green"))
>     painter.setPen(QtGui.QPen(QtGui.QBrush(QtGui.QColor"black")),
>                    BORDER_WIDTH))
>     painter.drawRect(x, y, w, h)
>
> As the scene is scaled according to its view size, to always fits,
> BORDER_WIDTH is not constant, but depends on the zoom factor (which I
> don't know, as I use fitInView()).
>
> Is there a way to always have a border of BORDER_WIDTH pixels, whatever
> the view size is?

I found the solution:

    def _computeBorderWidth(self):
        xRatio = self.scene().views()[0].width() / self.scene().width()
        yRatio = self.scene().views()[0].height() / self.scene().height()
        return BORDER_WIDTH / min(xRatio, yRatio)

-- 
    Frédéric

    http://www.gbiloba.org



More information about the PyQt mailing list