[PyQt] Re: how to show interactive Picture

Markus Feldmann feldmann_markus at gmx.de
Tue Feb 10 18:15:52 GMT 2009


To compare i post the example.
There are some commands in the example i didn't understand.

I do some notes in the Code !!!


#######################################################################
import sys
from PyQt4 import QtCore, QtGui

import basicdrawing_rc


class RenderArea(QtGui.QWidget):

     Line, Points, Polyline, Polygon, Rect, RoundRect, Ellipse, Arc, \
     Chord, Pie, Path, Text, Pixmap = range(13) ###WHAT SHALL THAT ???###

     def __init__(self, parent = None):
         QtGui.QWidget.__init__(self, parent)

         self.shape = RenderArea.Pixmap ###IS IT CALLING HIMSELF ???###
         self.pen = QtGui.QPen()
         self.brush = QtGui.QBrush()

         self.pixmap = QtGui.QPixmap()
         self.pixmap.load(":/images/qt-logo.png")


     def minimumSizeHint(self):
         return QtCore.QSize(100, 100)

     def sizeHint(self):
         return QtCore.QSize(400, 200)

     def setPen(self, pen):
         self.pen = pen
         self.update()

     def setBrush(self, brush):
         self.brush = brush
         self.update()

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

         painter.save()

         painter.drawPixmap(10, 10, self.pixmap)

         painter.restore()

         painter.end()


IdRole = QtCore.Qt.UserRole

class Window(QtGui.QWidget):
     def __init__(self, parent = None):
         QtGui.QWidget.__init__(self, parent)

         self.renderArea = RenderArea()
         mainLayout = QtGui.QGridLayout()
         mainLayout.addWidget(self.renderArea, 0, 0, 1, 2)
         self.setLayout(mainLayout)
         self.setWindowTitle(self.tr("Basic Drawing"))


if __name__ == "__main__":
     app = QtGui.QApplication(sys.argv)
     window = Window()
     window.show()
     sys.exit(app.exec_())
#######################################################################



More information about the PyQt mailing list