Mads Ipsen schrieb:
--------- Original Besked --------
Fra: Markus Feldmann <feldmann_mar...@gmx.de>
Til: pyqt@riverbankcomputing.com <pyqt@riverbankcomputing.com>
Emne: [PyQt] Re: how to show interactive Picture
Dato: 09/02/09 23:58

Mads Ipsen schrieb:
&gt; Could is be that you try to paint before the window is shown? You
need to
&gt; call show() before you can start painting. The following snippet
generates
&gt; an error similar to yours:
Hi,

This is not all of my Code. So there is a &lt;show()&gt; in my main source

code. This Source Code only shows a sub-widget of a MDI Application.

However this window is shown, but without the picture.
How do the program know in which widget shall the Pixmap
be shown ?

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Thats something you tell the program. You reimplement the method
'paintEvent' for a widget class like in the example I posted. Then for a
particular instance of the widget, the window is painted everytime a
paintEvent occurs and the widget get painted. A paintEvent event occurs eg.
when a window is hidden underneath another window and then shown.

To a draw a pixmap onto a widget do something like this in the paintEvent
method:

     def paintEvent(self, event):
        painter = QtGui.QPainter(64,64)
        pixmap = QtGui.QPixmap()

        painter.begin(self)
        painter.drawPixmap(0,0,pixmap)
        painter.end()

Mads
I think my Problem is that i have to send an envent?

As you wrote i changed some of my code. I parted my
scrollarea, where i want to paint my picture, and my
mainwindow, which is a MDI Sub-Widget. The scrollarea
will be centered into the MDI Sub-Widget.

class ScrollArea(QScrollArea):
    def __init__(self, parent=None):
        QScrollArea.__init__(self, parent)

        self.pen = QPen()
        self.brush = QBrush()
        self.pixmap = QPixmap()
        self.pixmap.load(":/../media/images/aventurien.jpg")

    def paintEvent(self,  event):
        painter =  QPainter()
        painter.begin(self)
        painter.setPen(self.pen)
        painter.setBrush(self.brush)

        painter.save()
        painter.drawPixmap(0,  0,  self.pixmap)
        painter.restore()
        painter.end()


class ReiseHelfer(QMainWindow):
    def __init__(self, parent=None):
        QMainWindow.__init__(self, parent)

        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)

        self.createActions()
        self.createMenus()
        self.createStatusBar()

        self.setWindowTitle(self.tr("Reisehelfer"))
        self.scrollArea = ScrollArea()
        self.setCentralWidget(self.scrollArea)

        self.readSettings()

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to