Attachment 'mdiarea_pixmap.py'

Download

   1 #!/usr/bin/env python
   2 
   3 import sys
   4 from PyQt4.QtCore import Qt
   5 from PyQt4.QtGui import *
   6 
   7 class MDIArea(QMdiArea):
   8 
   9     def __init__(self, background_pixmap, parent = None):
  10     
  11         QMdiArea.__init__(self, parent)
  12         self.background_pixmap = background_pixmap
  13         self.centered = False
  14     
  15     def paintEvent(self, event):
  16     
  17         painter = QPainter()
  18         painter.begin(self.viewport())
  19         
  20         if not self.centered:
  21             painter.drawPixmap(0, 0, self.width(), self.height(), self.background_pixmap)
  22         else:
  23             painter.fillRect(event.rect(), self.palette().color(QPalette.Window))
  24             x = (self.width() - self.display_pixmap.width())/2
  25             y = (self.height() - self.display_pixmap.height())/2
  26             painter.drawPixmap(x, y, self.display_pixmap)
  27         
  28         painter.end()
  29     
  30     def resizeEvent(self, event):
  31     
  32         self.display_pixmap = self.background_pixmap.scaled(event.size(), Qt.KeepAspectRatio)
  33 
  34 
  35 if __name__ == "__main__":
  36 
  37     app = QApplication(sys.argv)
  38     
  39     if len(app.arguments()) != 2:
  40     
  41         sys.stderr.write("Usage: %s <image path>\n" % sys.argv[0])
  42         sys.exit(1)
  43     
  44     m = MDIArea(QPixmap(sys.argv[1]))
  45     m.centered = True
  46     m.show()
  47     sys.exit(app.exec_())

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2014-06-07 13:34:56, 1.3 KB) [[attachment:mdiarea_pixmap.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.

Unable to edit the page? See the FrontPage for instructions.