Logo ROOT   6.07/09
Reference Guide
Namespaces
qtexample.py File Reference

Namespaces

 qtexample
 

Detailed Description

Qt example.

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

Definition in file qtexample.py.