Guest User

Graphicsview drawing

a guest
Apr 12th, 2012
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.97 KB | None | 0 0
  1. from PySide import QtCore, QtGui
  2. import sys
  3.  
  4. class Ui_fi(object):
  5.     '''
  6.    UI, auto-generated by using QtDesigner, do not change anything here,
  7.    but only in the .ui file with QtDesigner.
  8.    '''
  9.    
  10.     def setupUi(self, fi):
  11.         fi.setObjectName("fi")
  12.         fi.resize(603, 361)
  13.         self.zoneDessin = QtGui.QGraphicsView(fi)
  14.         self.zoneDessin.setGeometry(QtCore.QRect(80, 80, 421, 231))
  15.         self.zoneDessin.setObjectName("zoneDessin")
  16.  
  17.         self.retranslateUi(fi)
  18.         QtCore.QMetaObject.connectSlotsByName(fi)
  19.  
  20.     def retranslateUi(self, fi):
  21.         fi.setWindowTitle(QtGui.QApplication.translate("fi", "Essai de dessin", None, QtGui.QApplication.UnicodeUTF8))
  22.  
  23.  
  24. class Gui(QtGui.QMainWindow, Ui_fi):
  25.     '''Graphical user interface, without any logic'''
  26.    
  27.     def __init__(self):
  28.         super(Gui, self).__init__()
  29.         self.setupUi(self)
  30.  
  31.     def customPaint(self):
  32.         '''Example to draw some text and lines in the graphicsview'''
  33.        
  34.         scene = QtGui.QGraphicsScene(0, 0, 200, 200)
  35.         scene.addText("Hello Georges!")
  36.        
  37.         # Draw a box around the text
  38.         width = 110
  39.         height = 40
  40.         downX = width / 2
  41.         downY = height + 20
  42.         scene.addLine(0, 0, 0, height)
  43.         scene.addLine(width, height, downX, downY)
  44.         scene.addLine(0, height, downX, downY)
  45.         scene.addLine(width, 0, width, height)
  46.         scene.addLine(0, 0, width, 0)
  47.        
  48.         self.zoneDessin.setScene(scene)
  49.        
  50.        
  51. class Controller(object):
  52.     '''Controls interaction between view and logic'''
  53.    
  54.     def __init__(self):
  55.         self.view = Gui()
  56.        
  57.     def start(self):
  58.         '''Start the application'''
  59.        
  60.         self.view.customPaint()
  61.         self.view.show()
  62.        
  63.        
  64.  
  65. if __name__== "__main__":
  66.     app = QtGui.QApplication(sys.argv)
  67.     controller = Controller()
  68.     controller.start()
  69.     sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment