QGraphicsProxyWidget > Qlabel get mouseMove/Release events?
-
Hey
I'm trying to get an event response from my QLabel that is set to be QGraphicsProxyWidget.
In my QGraphicsView I set
void test::mouseMoveEvent(QMouseEvent *event){ if(itemAt(event->pos()){ return;} QGraphicsView::mouseMoveEvent(event); }
But no matter what I do, I cant get the events to show up in proxyWidget or QLabel itself. How can I forward them to the correct widget? The GraphicsView event dont match with QGraphicsSceneMouseEvent so I'm bit lost ?
Regards
Dariusz -
Hi
Normally the widget that are inserted into the proxy just works.See this small sample
#include <QGraphicsProxyWidget> #include <QGraphicsScene> #include <QGraphicsView> #include <QMessageBox> #include <QPushButton> #include <QDebug> int main(int argc, char** argv) { QApplication app(argc, argv); QPushButton* button = new QPushButton("CLICK ME"); QObject::connect(button, &QPushButton::clicked, [ = ]() { QMessageBox::warning(0, "Hello from widget", "Im alive"); } ); QGraphicsScene scene; QGraphicsProxyWidget* proxy = scene.addWidget(button); QGraphicsView view(&scene); view.show(); return app.exec(); }
Do you put them in an qgraphicsitemgroup ?
Also , normally a QLabel do not have any mousePressEvent override so i assume you use something like https://wiki.qt.io/Clickable_QLabel
to make it clickable. ? -
Hey
Mmmm tricky. I realized I did not need to use proxyWiwdget but QGraphicsPixmapItem was sufficient. So I stayed at View level and handled it all from there for now, but I'm still puzzled.Say you have
QGraphicsPixmapItem and you click on it and do mouse move. Would I like to forward the event from QGraphicsView to QGraphicsPixmapItem as that does not happen as standard? How can I do that? I think that View by default would attempt to move the item in the scene. But I don't want to do this. I just want to pass press/move/release events to the underlying item.
-
Hi
Can we talk about what goal is ?
If you think QGraphicsPixmapItem is what you need i guess that you first
tried to show pixmap in a QLabel.
Since the pixmap have no methods for handling any input in not really sure
why you try to forward events to it.Are you trying to make a clickable image or what is the overall goal ?
If yes, please see this
https://forum.qt.io/topic/60820/how-to-get-mouse-press-event-on-a-qpixmap/2 -
The more I think of it the less I want to forward events to it actually... well maybe not. I want to have different items and then change their event behavior based on their types. So I thought I could forward it to them. Lets say I have a list view, I would like to forward mouseWheelEvent scroll to it when mouse is over the widget. Same goes for QImage/Pixmap I wanted to try some paint effect where I could paint on image in QGraphicsView so I can move it around anywhere/etc/etc.
-
Hi
If you want special items, i suggest you just create your own classes by subclassing
QGraphicsItem. That way you can make them do whatever you like.Your example with ListView should work already as far as i know it can scroll with mouse3 but that needs a QGraphicsProxyWidget to function.
As far as i know, one should use Proxy if you insert Widgets in the scene for them to fully function.