2012-03-02 02:55:32 +00:00
|
|
|
from pyqtgraph.Qt import QtGui, QtCore
|
|
|
|
from pyqtgraph.GraphicsScene import GraphicsScene
|
2012-05-11 22:05:41 +00:00
|
|
|
from .GraphicsItem import GraphicsItem
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
__all__ = ['GraphicsWidget']
|
2012-04-16 20:45:55 +00:00
|
|
|
|
|
|
|
class GraphicsWidget(GraphicsItem, QtGui.QGraphicsWidget):
|
2012-03-02 02:55:32 +00:00
|
|
|
def __init__(self, *args, **kargs):
|
|
|
|
"""
|
2012-04-16 20:45:55 +00:00
|
|
|
**Bases:** :class:`GraphicsItem <pyqtgraph.GraphicsItem>`, :class:`QtGui.QGraphicsWidget`
|
|
|
|
|
2012-03-02 02:55:32 +00:00
|
|
|
Extends QGraphicsWidget with several helpful methods and workarounds for PyQt bugs.
|
2012-04-16 20:45:55 +00:00
|
|
|
Most of the extra functionality is inherited from :class:`GraphicsItem <pyqtgraph.GraphicsItem>`.
|
2012-03-02 02:55:32 +00:00
|
|
|
"""
|
|
|
|
QtGui.QGraphicsWidget.__init__(self, *args, **kargs)
|
2012-04-16 20:45:55 +00:00
|
|
|
GraphicsItem.__init__(self)
|
2012-03-02 02:55:32 +00:00
|
|
|
GraphicsScene.registerObject(self) ## workaround for pyqt bug in graphicsscene.items()
|
|
|
|
|
2012-05-24 00:20:54 +00:00
|
|
|
## Removed because this causes segmentation faults. Don't know why.
|
|
|
|
# def itemChange(self, change, value):
|
|
|
|
# ret = QtGui.QGraphicsWidget.itemChange(self, change, value) ## segv occurs here
|
|
|
|
# if change in [self.ItemParentHasChanged, self.ItemSceneHasChanged]:
|
|
|
|
# self._updateView()
|
|
|
|
# return ret
|
2012-05-15 02:05:53 +00:00
|
|
|
|
2012-03-02 02:55:32 +00:00
|
|
|
#def getMenu(self):
|
|
|
|
#pass
|
|
|
|
|
|
|
|
def setFixedHeight(self, h):
|
|
|
|
self.setMaximumHeight(h)
|
|
|
|
self.setMinimumHeight(h)
|
|
|
|
|
|
|
|
def setFixedWidth(self, h):
|
|
|
|
self.setMaximumWidth(h)
|
|
|
|
self.setMinimumWidth(h)
|
|
|
|
|
|
|
|
def height(self):
|
|
|
|
return self.geometry().height()
|
|
|
|
|
|
|
|
def width(self):
|
|
|
|
return self.geometry().width()
|
|
|
|
|
|
|
|
def boundingRect(self):
|
|
|
|
br = self.mapRectFromParent(self.geometry()).normalized()
|
|
|
|
#print "bounds:", br
|
|
|
|
return br
|
|
|
|
|
|
|
|
def shape(self): ## No idea why this is necessary, but rotated items do not receive clicks otherwise.
|
|
|
|
p = QtGui.QPainterPath()
|
|
|
|
p.addRect(self.boundingRect())
|
|
|
|
#print "shape:", p.boundingRect()
|
|
|
|
return p
|
|
|
|
|
|
|
|
|
2012-06-12 20:02:48 +00:00
|
|
|
|
|
|
|
def setParentItem(self, parent):
|
|
|
|
## Workaround for Qt bug: https://bugreports.qt-project.org/browse/QTBUG-18616
|
2012-06-18 18:00:19 +00:00
|
|
|
if parent is not None:
|
|
|
|
pscene = parent.scene()
|
|
|
|
if pscene is not None and self.scene() is not pscene:
|
|
|
|
pscene.addItem(self)
|
|
|
|
return QtGui.QGraphicsObject.setParentItem(self, parent)
|