PDA

View Full Version : Issue while overloading mouseReleaseEvent



Thierry
15th February 2010, 21:42
Hi,

I have a strange issue between a QPushButton and my QToolBar. Basically, I override QPushButton to support right click events. When a user right click on the button, I overide mouseReleaseEvent and it emits a new custom signal. Another class deriving from QWidget connect this signal to a local slot. If this slot call a exec() method from a dialog, the dialog appear ok, but when the dialog close, a QMenu appear. This QMenu is the one generated by QToolBar when right clicking on the toolbar. As far as I'm concerned, the button and the toolbar are unrelated and the mouse was no where near the toolbar on the right click event.

So I can only assume that the right click event somehow propaged itself to the toolbar. If I change the exec() for a show() (and declare the dialog static), I don't see this problem.

I'm not sure if this description is clear enough... I will wait before posting a bunch of code.

Somebody has an idea?

Thanks!

Lykurg
15th February 2010, 21:51
A minimal compileable program would be nice to do some tests. One thing came in my mind while reading. Try if it helps if you call QEvent::accept() in the event handler of your button.

Thierry
15th February 2010, 22:26
Hi, Thanks for your answer.

Accepting the event didn't change the behavior... I will work on a small example to recreate the problem.

Thierry
16th February 2010, 00:09
Here is a small example showing the problem... I'm attaching the files if somebody want to try it out. Since this example is so small, the problem must come for the derived class of QPushButton. Here is the code:

.h


#ifndef MULTI_MOUSE_CLICK_BUTTON_H
#define MULTI_MOUSE_CLICK_BUTTON_H

#include <QPushButton>

class multiMouseClickButton : public QPushButton
{
Q_OBJECT

public:

multiMouseClickButton(QWidget* myParent = 0);

signals:

void multiMouseLeftClicked();
void multiMouseMiddleClicked();
void multiMouseRightClicked();

protected:

void mousePressEvent(QMouseEvent*);
void mouseReleaseEvent(QMouseEvent*);

private:
};

#endif


.cpp


#include <QMouseEvent>

#include "multiMouseClickButton.h"

multiMouseClickButton::multiMouseClickButton(QWidg et* myParent)
: QPushButton(myParent)
{
}

void multiMouseClickButton::mousePressEvent(QMouseEvent * myEvent)
{
setDown( true );
}

void multiMouseClickButton::mouseReleaseEvent(QMouseEve nt* myEvent)
{
if(isDown())
{
switch(myEvent->button())
{
case Qt::LeftButton:
emit(multiMouseLeftClicked());
break;

case Qt::MidButton:
emit(multiMouseMiddleClicked());
break;

case Qt::RightButton:
emit(multiMouseRightClicked());
break;

default:
break;
}
}

setDown( false );
}
4288

Lykurg
16th February 2010, 09:27
I'm sorry, but it works fine on my computer. (last Kubuntu and Qt 4.6.1)

right click on the button => dialogue appears => click there ok => dialogue disappears => NO context menu.

Thierry
16th February 2010, 15:14
I'm using Qt4.5 on mingw... Maybe it's a bug related to this specific config.

I will try with mingw/Qt4.6 and on a Linux box.

This what I'm getting after a right click with this code:

4292

Thierry
16th February 2010, 17:23
It's working on Linux.

I tried on Qt4.6 mingw (the latest February 2010 release) and the issue is still there. Apparently this is a Qt bug on mingw.

I'm not sure where should I go from here... I guess I will report the problem.

Lykurg
16th February 2010, 17:26
I'm not sure where should I go from here... I guess I will report the problem.
Strange. Yes, open a new ticket on the Qt Bug Tracker (if it does not exist a similar ticket.)