Did you try setting QGraphicsItem::setAcceptsHoverEvents to true on the items ??
Did you try setting QGraphicsItem::setAcceptsHoverEvents to true on the items ??
no, since I don't need hover events, juts plain click and move mouse events.
But thanks for the suggestion.
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
in order to debug this I sub classed QGrapicsScene.
The mouse event (in this case click event) gets delivered to the scene.
In the mouse event handler in the scene however, if I ask mouseGrabberItem() - I get -> 0, which means no item is grabbing the mouse - which means no item is getting mouse events.
Any idea idea what could be causing this?
I can't recall nor do I see this in the docs that I need to explicitly enable mouse grabbing on items since its a default behaviour (beyond setting the selectable flag).
(I am using Qt4.3 in this case, and grabMouse() is not yet available. But this should not be needed any how...)
EDIT:
all the items return true on acceptedMouseButtons ().testFlag( Qt::LeftButton)
help?
Last edited by high_flyer; 16th July 2008 at 16:29.
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
Do you call the base class implementation of the view's mouse events? You need to do that in order for events to be delivered to items.
Can u post some code which mimicks this behaviour.
I tried catching mousePressEvent in of my code, and I do get the events. And I have these flags set - setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); .
Probably you are missing some thing.
QUERY : Are you calling base class QGraphicsScene::mousePressEvent() from you scene class ?? I guess you are not. I dont see any other reason unless we see ur code
EDIT:
Wysota posted before me, and ya it must be base class of view,,, not scene![]()
Last edited by aamer4yu; 16th July 2008 at 18:44.
Hi,
@wysota:
yes I do.
Here is the class chain mouse press evets:
The QGraphicsView subclass (this gets called):
Qt Code:
{ if(event->button() == Qt::RightButton) { //do some stuff event->accept(); } else event->ignore(); }To copy to clipboard, switch view to plain text mode
The Scene subclass (this gets called), and "no mouse grabber" is also being printed:
Qt Code:
{ std::cout<<"scene event"<<std::endl; if(!mouseGrabberItem()) std::cout<<"no mouse grabber"<<std::endl; }To copy to clipboard, switch view to plain text mode
the QGrphicsRectItem subclass - not getting called (but that is no surprise since there is no mouse grabber item in the scene - but I don't know why)
Qt Code:
{ } { std::cout<<"CPLContainer mouse clicked"<<std::endl; }To copy to clipboard, switch view to plain text mode
Thanks again for the help.
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
I don't like the event->ignore() line of yours. Don't you think you should ignore an event if and only if both your handler and the base handler wants to ignore the event? It might be that the default handler accepts the event, but it gets ignored because you ignore it as it was not caused by right click and because of that Something Bad Happens. I don't know if that is the source of your problem (I doubt it), but you should double check that anyway. Despite that I think your item's handler should be getting called... Try extracting the smallest possible chunk of code that reproduces the problem.
Why do you call setBoundingRect and not setRect in your CPLContainer constructor? Perhaps your rect is empty and thus gets no mouse events?
Thanks for you answers guys.
@wysota: the ignore is not a problem since it is only present in the QGraphicsView subclass, and the scene does get the event.
In addition, the original code did not have the ignore in it, I just added it as I started trying all kinds of things.
In order to make a long story short, attached is a project (kdevelop) which illustrates the problem. (only three basically empty classes and a main)
Maybe you can then help me find what it is that I am doing wrong.
I know I am doing something wrong which is basic, but I really just don't see what!
@caduel: setBaoundingRect() ( in my code) sets the rect that is returned by boundingRect(), which is the important thing.
But in the code attached even this is stripped off (bounding rect is hard coded), and still the same behaviour.
I really appreciate the help!
Thanks.
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
i) note besides: the Makefile in your zip does not work for others
ii) using Qt4.4 (Linux) your code seems to work
running your app and clicking the red rectangle, I get:
Hello from Qt 4!
view pressed
QCTimelineScene: mousePressEvent
scene clicked
view pressed
QCTimelineScene: mousePressEvent
scene clicked
view pressed
QCTimelineScene: mousePressEvent
Should it do more?
of course not - this is why you have the pro file, run qmake on in it first! :-)i) note besides: the Makefile in your zip does not work for others
yes it should do more - notice that the red rectangle item does not get the mouse click - only the view and the scene.
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
add
to your constructor.
The boundingRect is not enough...
high_flyer (23rd July 2008)
thanks!
You are correct!
But then I don't understand the docs.
In the docs it says:
why is boundingRect() pure virtual if setRect() must be called as well?To write your own graphics item, you first create a subclass of QGraphicsItem, and then start by implementing its two pure virtual public functions: boundingRect(), which returns an estimate of the area painted by the item, and paint(), which implements the actual painting.
Hmm. oh well, no time for that now, I need to work - big thanks!
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
Bookmarks