PDA

View Full Version : Set mouse tracking issue



sajis997
24th January 2012, 05:30
Hello forum

let me re-iterate what is written in the Qt manual about mouse tracking:

"This property holds whether mouse tracking is enabled for the widget.
If mouse tracking is disabled (the default), the widget only receives mouse move events when at least one mouse button is pressed while the mouse is being moved.
If mouse tracking is enabled, the widget receives mouse move events even if no buttons are pressed."


I have sub-classed QGraphicsView and did not enable mouse tracking inside the subclass construcor.


But the mouse move is tracked inside the mouse move event even when no mouse buttons are pressed.


Any explanation ? I am using Qt 4.4.3



Regards
Sajjad

ChrisW67
24th January 2012, 07:23
You are saying that this always outputs "Move" messages regardless of mouse buttons:

#include <QtGui>
#include <QDebug>

class MyView: public QGraphicsView {
Q_OBJECT
public:
MyView(QWidget *p = 0): QGraphicsView(p)
{
resize(QSize(320, 240));
qDebug() << hasMouseTracking(); // outputs false
}

protected:
void mouseMoveEvent( QMouseEvent * event )
{
qDebug() << "Move";
}
};


int main(int argc, char *argv[])
{
QApplication app(argc, argv);

MyView m;
m.show();

return app.exec();
}
#include "main.moc"

Certainly doesn't here with Qt 4.7.4.

Post a small, compilable example that demonstrates the problem.

sajis997
24th January 2012, 15:38
Hello ChrisW67,

I have made some changes within the diagram scene example and mouse tracking is set to false explicitly and still i get the mouse tracking enabled in Qt 4.4.3.


Please check it out if this is one of the bugs inside it or is it something that i am missing while re-engineering ?



Regards
Sajjad

wysota
24th January 2012, 23:47
Mouse tracking is enabled on the viewport. This is caused by the following call:


setTransformationAnchor(AnchorUnderMouse);

sajis997
25th January 2012, 00:37
Thanks

Is there any reference to this informational hint or you digged down to the source ?



Regards
Sajjad

wysota
25th January 2012, 00:56
I did what you should have done. I took your code and started commenting out lines that might have enabled features requiring mouse tracking. This was the second thing I tried.