PDA

View Full Version : mousePressEvent problem



jhowland
14th April 2010, 22:16
I have reimplemented mousePressEvent inside of a QGLWidget. It never gets called.

I have also reimplemented mouseMoveEvent in the same widget (as recounted in an earlier post). It gets called satisfactorily.

I dont think there is anything odd about my function:





void ImageGLView::mousePressEvent(QMouseEvent *event)
{
if(FLOATING_DOT == mouseMode){
QPoint currentPos = event->pos();
lastPos = currentPos;
}

}



and here is the .h


protected:

void initializeGL();
void paintGL();

void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event);


Is there something special I need to know about reimplementing mousePressEvents? I tried implementing it on the parent of my QGLWidget, and it indeed got called when I clicked in the non-covered up part of the parent--

I am setting stereo mode on the QGLWidget, but it doesn't seem to make any difference when I dont do so.

I'm baffled, and would greatly appreciate any help. My apologies if this seems like a repost, but my last query was asking for help with mouseMoveEvent, and after I solved my move problem and posed my press problem, I never got any responses

high_flyer
15th April 2010, 10:24
How do you know it is not being called?
Put a break point on the first line and see if it gets caught, may be( FLOATING_DOT == mouseMode ) is false.

zgulser
15th April 2010, 12:13
Or replace mouseMoveEvent and mousePressEvent..I mean get the pressEvent just top of the moveEvent and try..

jhowland
15th April 2010, 14:13
How do you know it is not being called?
Put a break point on the first line and see if it gets caught, may be( FLOATING_DOT == mouseMode ) is false.

This is how I know it is not being called--I have done just what you suggested

jhowland
15th April 2010, 14:14
not sure what you mean by this. Are you saying to re-order the functions? Why would that matter?

jhowland
15th April 2010, 14:16
Or replace mouseMoveEvent and mousePressEvent..I mean get the pressEvent just top of the moveEvent and try..

not sure what you mean by this. Are you saying to re-order the functions? Why would that matter?

ps: sorry about the unquoted reply that probably didn't make much sense with no context, it's early in the workday...

zgulser
16th April 2010, 06:49
Are you saying to re-order the functions?


Exactly..Once I've faced with such a problem. And after I replace the regarding functions, it was OK.

stefanadelbert
16th April 2010, 09:13
I was having what sounds like a similar problem recently where a custom QWidget (comprising QPushButton and QSpinBox) was being added to a QMenu as a QWidgetAction. I wanted a click (or mouseReleaseEvent) from the QPushButton to "activate" the QActionWidget.

I had to do a little work to get the mouseReleaseEvent to propagate through to the QMenu (using this (http://lists.trolltech.com/qt-interest/2007-06/thread00463-0.html) post). I managed to catch execution in QMenu::activate, but d->mouseDown was not set. I think it had to do with clicking on the QPushButton which was not being considered to be "inside" the QWidgetAction and therefore failing to actually properly activate the QWidgetAction. This is the thread (http://www.qtcentre.org/threads/29852-Popup-Menu-not-closing-after-clicking-custom-widget?highlight=mouseDown).

I solved my problem with a simple workaround, but would like to get it working using events properly.

EDIT: I just had a look at your code snippet again. I think you might need to call mousePressEvent on your base class in void ImageGLView::mousePressEvent(QMouseEvent *event).

i.e.

void ImageGLView::mousePressEvent(QMouseEvent *event)
{
if(FLOATING_DOT == mouseMode){
QPoint currentPos = event->pos();
lastPos = currentPos;
}
QBaseClass::mousePressEvent(event);
}

EDIT: I take it back - I reread you post and I realised that your mousePressEvent isn't even being called. Is the base class mousePressEvent being called when clicking inside QGLWidget (unlikely)? Is the parent's mousePressEvent being called when you click inside the QGLWidget (should happen under normal circumstances, as far as I understand)?

jhowland
16th April 2010, 17:25
I was having what sounds like a similar problem recently where a custom QWidget (comprising QPushButton and QSpinBox) was being added to a QMenu as a QWidgetAction. I wanted a click (or mouseReleaseEvent) from the QPushButton to "activate" the QActionWidget.

I had to do a little work to get the mouseReleaseEvent to propagate through to the QMenu (using this (http://lists.trolltech.com/qt-interest/2007-06/thread00463-0.html) post). I managed to catch execution in QMenu::activate, but d->mouseDown was not set. I think it had to do with clicking on the QPushButton which was not being considered to be "inside" the QWidgetAction and therefore failing to actually properly activate the QWidgetAction. This is the thread (http://www.qtcentre.org/threads/29852-Popup-Menu-not-closing-after-clicking-custom-widget?highlight=mouseDown).

I solved my problem with a simple workaround, but would like to get it working using events properly.

EDIT: I just had a look at your code snippet again. I think you might need to call mousePressEvent on your base class in void ImageGLView::mousePressEvent(QMouseEvent *event).

i.e.

void ImageGLView::mousePressEvent(QMouseEvent *event)
{
if(FLOATING_DOT == mouseMode){
QPoint currentPos = event->pos();
lastPos = currentPos;
}
QBaseClass::mousePressEvent(event);
}

EDIT: I take it back - I reread you post and I realised that your mousePressEvent isn't even being called. Is the base class mousePressEvent being called when clicking inside QGLWidget (unlikely)? Is the parent's mousePressEvent being called when you click inside the QGLWidget (should happen under normal circumstances, as far as I understand)?

no, the base class mousePressEvent is NOT being called,or does it appear that the parents mousePressEvent is being called

stefanadelbert
18th April 2010, 23:53
The parent's mousePressEvent should get called, unless the event is not being passed up for some reason.

Maybe try reimplementing mouseReleaseEvent in QGLWidget and see if that is called.