def _updatePen(self, pen):
        """Update the pen to the currently selected one."""

        # line style
        style = {
            qt.Qt.NoPen: pyemf.PS_NULL,
            qt.Qt.SolidLine: pyemf.PS_SOLID,
            qt.Qt.DashLine: pyemf.PS_DASH,
            qt.Qt.DotLine: pyemf.PS_DOT,
            qt.Qt.DashDotLine: pyemf.PS_DASHDOT,
            qt.Qt.DashDotDotLine: pyemf.PS_DASHDOTDOT,
            qt.Qt.CustomDashLine: pyemf.PS_USERSTYLE,
        }[pen.style()]

        if style != pyemf.PS_NULL:
            # set cap style
            style |= {
                qt.Qt.FlatCap: pyemf.PS_ENDCAP_FLAT,
                qt.Qt.SquareCap: pyemf.PS_ENDCAP_SQUARE,
                qt.Qt.RoundCap: pyemf.PS_ENDCAP_ROUND,
            }[pen.capStyle()]

            # set join style
            style |= {
                qt.Qt.MiterJoin: pyemf.PS_JOIN_MITER,
                qt.Qt.BevelJoin: pyemf.PS_JOIN_BEVEL,
                qt.Qt.RoundJoin: pyemf.PS_JOIN_ROUND,
                qt.Qt.SvgMiterJoin: pyemf.PS_JOIN_MITER,
            }[pen.joinStyle()]

            # use proper widths of lines
            style |= pyemf.PS_GEOMETRIC

        width = int(pen.widthF()*scale)
        qc = pen.color()
        color = (qc.red(), qc.green(), qc.blue())
        self.pencolor = color

        if pen.style() == qt.Qt.CustomDashLine:
            # make an extended pen if we need a custom dash pattern
            dash = [int(pen.widthF()*scale*f) for f in pen.dashPattern()]
            newpen = self.emf._appendHandle( _EXTCREATEPEN(
                style, width=width, color=color, styleentries=dash))
        else:
            # use a standard create pen
            newpen = self.emf.CreatePen(style, width, color)
        self.emf.SelectObject(newpen)

        # delete old pen if it is not a stock object
        if not isStockObject(self.pen):
            self.emf.DeleteObject(self.pen)
        self.pen = newpen