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