Drag to pyqtgraph widget

705 views
Skip to first unread message

Leonid Rumatov

unread,
Jan 13, 2014, 10:32:58 PM1/13/14
to pyqt...@googlegroups.com
Hello, all!

I want to drag some to pyqtgraph. So, I did this:

class my_pyqtgraph_widget()
  def def dragEnterEvent(self, ev):
       ...
  def dropEvent(self, ev):
    ......


dragEnterEvent worked, but the dropEvent - not invoked. I got this message:

QGraphicsItem::ungrabMouse: not a mouse grabber

I start to dig information in the Internet and found, that I should reimplement this function in QGraphicsScene, not in Widget.
Assume that this is correct, so, I go to the pyqtgraph's GraphicsScene.py. There I found the 

def mouseReleaseEvent(self, ev):
 ...

That, as I can see, handle drag events. But, I can't understand, how to use it.

So, can I use pyqtgraph's specific to handle drag-n-drop, or I must follow pure-Qt way?


Luke Campagnola

unread,
Jan 14, 2014, 2:20:36 PM1/14/14
to pyqt...@googlegroups.com
On Mon, Jan 13, 2014 at 10:32 PM, Leonid Rumatov <dondu...@yandex.ru> wrote:
I want to drag some to pyqtgraph. So, I did this:

class my_pyqtgraph_widget()
  def def dragEnterEvent(self, ev):
       ...
  def dropEvent(self, ev):
    ......

dragEnterEvent worked, but the dropEvent - not invoked. I got this message:

QGraphicsItem::ungrabMouse: not a mouse grabber

What is the superclass of my_pyqtgraph_widget? If it is a QGraphicsView (including pg.GraphicsView and pg.PlotWidget), then you need a few things:

1) call self.setAcceptDrops(True)
2) override dragEnterEvent(event) and make sure to call event.accept()
3) override dragMoveEvent, since QGraphicsView will ignore these by default. 


I start to dig information in the Internet and found, that I should reimplement this function in QGraphicsScene, not in Widget.
Assume that this is correct, so, I go to the pyqtgraph's GraphicsScene.py. There I found the 

You can also implement drops through QGraphicsScene, but I think it's much easier on the widget (unless you want specific items within the scene to receive the drop events)
 

def mouseReleaseEvent(self, ev):
 ...

That, as I can see, handle drag events. But, I can't understand, how to use it.

This is used for handling mouse drags, such as when zooming/panning in a ViewBox, or when dragging ROI handles. It does not interact in any way with Qt's drag/drop system.

More reading here:


Luke

Слава

unread,
Jan 14, 2014, 10:04:23 PM1/14/14
to Luke Campagnola
Hello, Luke.

Thank you for the answer.
I did the drag-n-drop.

In details:
Yep, my_pyqtgraph_widget inherits pg.PlotWidget.
I had to invoke setAcceptDrops(True) for the PlotItem.

This is pure-Qt code.
Luke

-- 
You received this message because you are subscribed to a topic in the Google Groups "pyqtgraph" group.
To unsubscribe from this topic, visit 
https://groups.google.com/d/topic/pyqtgraph/OKY-Y_rSlL4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pyqtgraph+...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyqtgraph/CACZXET_TJ1Z_bj61TXQ%3D8MaPhKgGzCU51netLzxN_v36KV9kDw%40mail.gmail.com.
For more options, visit 
https://groups.google.com/groups/opt_out.



-- 
Best wishes!
 Слава                            
mailto:dondu...@yandex.ru
Reply all
Reply to author
Forward
0 new messages