[PyQt] Re: how to show interactive Picture
David Boddie
david at boddie.org.uk
Tue Feb 10 22:48:13 GMT 2009
On Tue, 10 Feb 2009 22:42:24 +0100, Markus Feldmann wrote:
>
> I go it. :-)
:-)
> I am not sure, but maybe i have to set a Widget in
> the ScrollArea, and in this Widget i may paint?
That's the idea, yes.
> Here is my Code:
[...]
> class ScrollArea(QScrollArea):
> def __init__(self, parent=None):
> QScrollArea.__init__(self, parent)
>
> self.imagelabel = QLabel()
> self.image = QImage("./media/images/aventurien.jpg")
> self.imagelabel.setPixmap(QPixmap.fromImage(self.image))
> self.setWidget(self.imagelabel)
Here, because you are using a QLabel to show the image, it should
automatically appear correctly in the QScrollArea.
(Aside: If you create your own custom widget (by subclassing QWidget), you
have to reimplement the sizeHint() method as well as the paintEvent() method
to make it appear correctly in a QScrollArea. By using a standard widget
designed to show an image, you neatly avoid this problem.)
> 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.scrollArea.setBackgroundRole(QPalette.Dark)
> self.setCentralWidget(self.scrollArea)
>
> self.readSettings()
> ...
This should work. I'll post comments on your earlier message about the
Basic Drawing example in a separate message. You might also find it
useful to look at the Image Viewer example (widgets/imageviewer).
David
More information about the PyQt
mailing list