Can you please clear about this?But I'm confused that the contentsMouseMoveEvent() is only called when a mousebutton pressed and moved just as mouseTracking is FALSE.
Can you please clear about this?But I'm confused that the contentsMouseMoveEvent() is only called when a mousebutton pressed and moved just as mouseTracking is FALSE.
I dont know about Qt3 ...
but i guess u are overriding the wrong function...
setMouseTracking(true) enables the widget to receive mouseMoveEvent() ....not contentsMouseMoveEvent ...
try catching the events in mouseMoveEvent..
Hope this helps
Are you sure ?? i saw Q3CanvasView and it is derived from QWidget ... isnt QCanvasView derived from QWidget ??But in the QanvasView the contentsMouseMoveEvent is the only function that can receive the mouseMoveEvent.
If it is derived, then u can override the mouseMoveEvent.... try it
The QCanvasView is derived from QScrollView, the contentsMouseMoveEvent() is the member function of QScrollView. And also as the Qt documents example described, when you want to deal with mouseMoveEvent, mouePressEvent, mouseReleaseEvent etc. in the QCanvasView you can directly reimplement the contentsMouse****Event() which are all the member function of the QScrollView.
I'm not sure, but maybe you have to enable the mouse tracking on the viewport widget like in many corresponding situations you have to do in Qt4?
J-P Nurmi
What does it mean by "enable the mouse tracking on the viewport widget"?
What is viewport widget? I have only CanvasView wthin a QWidgetStack.
See QScrollView::viewport().
Try:
Qt Code:
viewport()->setMouseTracking(TRUE);To copy to clipboard, switch view to plain text mode
J-P Nurmi
should work....Qt Code:
viewport()->setMouseTracking(TRUE);To copy to clipboard, switch view to plain text mode
YES!That does work!
Thank you guys very much and best regards!
Could anybody are willing to compile the code and run it ?
When you run it ,you can click the Graphic button to switch to the QCanvasView. Then you hold the left mouse button dow and move it. Finally you can find the output
"The MouseMoveEvent has been received!" on the console. That means the QCanvasView receives the mouseMoveEvent correctly.
But when you just move the mouse without any button pressed down. There is no output on the console. So that means QCanvasView can not receive the mouseMoveEvent in the condition of no mouse button pressed down.
I hope that you can try it on practice. You will see the problem more clearly.
Thanks a lot!
That means, when I hold a mouse button down and move the mouse, the mouseMoveEvent is sent correctly. And then the contentsMouseMoveEvent() in the CanvasView receives the move event correctly too.
BUT as I mentioned before, I have already set the CanvasView's mouseTracking to TRUE!
That means, the contentsMouseMoveEvent() can receive mouseMoveEvent even if when mouse move WITHOUT any mouse button pressed! But now the CanvasView can't receive the mouseMoveEvent by mouse moving WITHOUT any mouse button pressed!
It seems that the code below doesn't work.
That is what I'm confused about.Qt Code:
CanvasView::CanvasView(QCanvas* canvas, QWidget* parent, const char* name) :QCanvasView(canvas,parent,name) { setMouseTracking(TRUE);}To copy to clipboard, switch view to plain text mode
Last edited by luffy27; 26th April 2007 at 07:54.
Bookmarks