ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qtexample.py
Go to the documentation of this file.
1 import sys
2 from PyQt4.QtGui import *
3 from PyQt4.QtCore import *
4 
5 
6 import ROOT
7 import sip
8 
9 class window(QMainWindow):
10  def __init__(self):
11  # Init the main window.
12  QMainWindow.__init__(self)
13  self.resize(350, 350)
14 
15  # Create the central widget.
16  self.CentralWidget = QWidget(self)
17  self.setCentralWidget(self.CentralWidget)
18  self.Layout = QGridLayout(self.CentralWidget)
19 
20  # Create a button.
21  self.QuitButton = QPushButton(self.centralWidget())
22  self.QuitButton.setText('Quit')
23  self.Layout.addWidget(self.QuitButton, 1, 0)
24  # Connect the button.
25  QObject.connect(self.QuitButton, SIGNAL('clicked()'), self.quit)
26 
27  # Create a root histogram.
28  self.hist = ROOT.TH1F("pipo","pipo", 100, 0, 100)
29 
30  # Create the main TQtWidget (using sip to get the pointer to the central widget).
31  self.Address = sip.unwrapinstance(self.CentralWidget)
32  self.Canvas = ROOT.TQtWidget(sip.voidptr(self.Address).ascobject())
33  ROOT.SetOwnership( self.Canvas, False )
34 
35  # Place the TQtWidget in the main grid layout and draw the histogram.
36 
37  self.Layout.addWidget(sip.wrapinstance(ROOT.AddressOf(self.Canvas)[0],QWidget), 0, 0)
38  self.hist.Draw()
39 
40  def quit(self):
41  print 'Bye bye...'
42  self.close()
43  ROOT.gApplication.Terminate()
44 
45 
46 if __name__ == '__main__':
47  application = qApp
48  terminator = ROOT.TQtRootSlot.CintSlot()
49  termAddress = sip.wrapinstance(ROOT.AddressOf(terminator)[0],QObject)
50  QObject.connect(application, SIGNAL("lastWindowClosed()"),termAddress ,SLOT("Terminate()"))
51  w = window()
52  w.show()
53  ROOT.gApplication.Run(1)
54  print 'Bye forever!'