2012-03-02 02:55:32 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
## Add path to library (just for examples; you do not need this)
|
2012-12-26 22:51:52 +00:00
|
|
|
import initExample
|
2012-03-02 02:55:32 +00:00
|
|
|
|
2012-03-02 03:58:02 +00:00
|
|
|
from pyqtgraph.Qt import QtCore, QtGui
|
2012-03-02 02:55:32 +00:00
|
|
|
import pyqtgraph as pg
|
|
|
|
from pyqtgraph.GraphicsScene import GraphicsScene
|
|
|
|
|
2021-01-27 18:59:07 +00:00
|
|
|
app = pg.mkQApp("GraphicsScene Example")
|
2012-03-02 02:55:32 +00:00
|
|
|
win = pg.GraphicsView()
|
|
|
|
win.show()
|
|
|
|
|
|
|
|
|
|
|
|
class Obj(QtGui.QGraphicsObject):
|
|
|
|
def __init__(self):
|
|
|
|
QtGui.QGraphicsObject.__init__(self)
|
|
|
|
GraphicsScene.registerObject(self)
|
|
|
|
|
|
|
|
def paint(self, p, *args):
|
|
|
|
p.setPen(pg.mkPen(200,200,200))
|
|
|
|
p.drawRect(self.boundingRect())
|
|
|
|
|
|
|
|
def boundingRect(self):
|
|
|
|
return QtCore.QRectF(0, 0, 20, 20)
|
|
|
|
|
|
|
|
def mouseClickEvent(self, ev):
|
|
|
|
if ev.double():
|
2012-05-11 22:05:41 +00:00
|
|
|
print("double click")
|
2012-03-02 02:55:32 +00:00
|
|
|
else:
|
2012-05-11 22:05:41 +00:00
|
|
|
print("click")
|
2012-03-02 02:55:32 +00:00
|
|
|
ev.accept()
|
|
|
|
|
|
|
|
#def mouseDragEvent(self, ev):
|
|
|
|
#print "drag"
|
|
|
|
#ev.accept()
|
|
|
|
#self.setPos(self.pos() + ev.pos()-ev.lastPos())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vb = pg.ViewBox()
|
|
|
|
win.setCentralItem(vb)
|
|
|
|
|
|
|
|
obj = Obj()
|
|
|
|
vb.addItem(obj)
|
|
|
|
|
|
|
|
obj2 = Obj()
|
|
|
|
win.addItem(obj2)
|
|
|
|
|
|
|
|
def clicked():
|
2012-05-11 22:05:41 +00:00
|
|
|
print("button click")
|
2012-03-02 02:55:32 +00:00
|
|
|
btn = QtGui.QPushButton("BTN")
|
|
|
|
btn.clicked.connect(clicked)
|
|
|
|
prox = QtGui.QGraphicsProxyWidget()
|
|
|
|
prox.setWidget(btn)
|
|
|
|
prox.setPos(100,0)
|
|
|
|
vb.addItem(prox)
|
|
|
|
|
|
|
|
g = pg.GridItem()
|
|
|
|
vb.addItem(g)
|
|
|
|
|
2012-12-05 05:25:45 +00:00
|
|
|
if __name__ == '__main__':
|
2021-03-22 18:17:12 +00:00
|
|
|
pg.mkQApp().exec_()
|