I'm trying to embed a PlotWidget in a QGraphicsItem, but it seems like
mousePress/Move/Release events are being consumed by the container widget
and not forwarded to the plot (but hover and scroll events still work as
expected). This breaks all click-based functionality of the plot. If I just
embed the PlotWidget directly using QGraphicsProxyWidget (and without a
container QWidget), then mouse events function correctly. Is there anything
that I'm missing in getting the mouse events to register when a PlotWidget
is in a embedded QWidget container?
The following snippet should demonstrate the problem:
from PyQt5 import QtWidgets, QtCore, QtGui
import pyqtgraph as pg
import numpy as np
def main():
app = QtWidgets.QApplication([])
view = QtWidgets.QGraphicsView()
scene = QtWidgets.QGraphicsScene(parent=view)
view.setScene(scene)
plot = pg.PlotWidget()
curve = plot.plot()
# uncomment to disable PlotWidget click functionality
# container_widget = QtWidgets.QWidget()
# layout = QtWidgets.QHBoxLayout(container_widget)
# layout.addWidget(plot)
# layout.setContentsMargins(0, 0, 0, 0)
# container_widget.setLayout(layout)
# plot = container_widget
xs = list()
ys = list()
idx = 0
def update():
nonlocal idx
curve.setData(x=xs, y=ys)
xs.append(idx)
ys.append(np.sin(idx / 20))
idx += 1
return
proxy = QtWidgets.QGraphicsProxyWidget()
proxy.setWidget(plot)
proxy.setGeometry(QtCore.QRectF(0, 0, 600, 600))
x, y, w, h = plot.x(), plot.y(), plot.width(), plot.height()
border_size = 10
container = QtWidgets.QGraphicsRectItem()
container.setPen(QtGui.QPen(QtGui.QColor(0, 0, 0)))
container.setBrush(QtGui.QBrush(QtGui.QColor(100, 100, 100)))
container.setRect(x - border_size, y - border_size, w + 2 *
border_size, h + 2 * border_size)
proxy.setParentItem(container)
scene.addItem(container)
timer = QtCore.QTimer()
timer.timeout.connect(update)
timer.start(10)
view.resize(800, 800)
view.show()
app.exec_()
if __name__ == '__main__':
main()
--
You received this message because you are subscribed to the Google Groups
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pyqtgraph/9f6e31d4-f9fb-4eb3-8a4b-24fb9fedbb54%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.