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>
{
Q_OBJECT
public:
multiMouseClickButton
(QWidget* myParent
= 0);
signals:
void multiMouseLeftClicked();
void multiMouseMiddleClicked();
void multiMouseRightClicked();
protected:
private:
};
#endif
#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
To copy to clipboard, switch view to plain text mode
.cpp
#include <QMouseEvent>
#include "multiMouseClickButton.h"
multiMouseClickButton
::multiMouseClickButton(QWidget* myParent
) {
}
void multiMouseClickButton
::mousePressEvent(QMouseEvent* myEvent
) {
setDown( true );
}
void multiMouseClickButton
::mouseReleaseEvent(QMouseEvent* 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 );
}
#include <QMouseEvent>
#include "multiMouseClickButton.h"
multiMouseClickButton::multiMouseClickButton(QWidget* myParent)
: QPushButton(myParent)
{
}
void multiMouseClickButton::mousePressEvent(QMouseEvent* myEvent)
{
setDown( true );
}
void multiMouseClickButton::mouseReleaseEvent(QMouseEvent* 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 );
}
To copy to clipboard, switch view to plain text mode
[ATTACH]qt_test.zip[/ATTACH]
Bookmarks