No mouseButtonRelease detected
Hello !
I'm working on a Warcraft 2-like game, and I'm currently making the selection of several units.
I have a MapView :
Code:
#include <QGraphicsView>
namespace Interface
{
class MainWindow;
{
protected:
MainWindow* window;
public:
void update();
};
}
The Map View is where there I can see my units and select them. I have already implement something to select just one unit, using MouseButtonPress event like that :
Code:
{
if(event
->type
() == QEvent::MouseButtonPress)
{
QPointF p
= mapToScene
(mapFromParent
(m
->pos
()));
// if in the map
int size = GAME.getMap().getSize();
if(p.x() >= 0 && p.y() >= 0 && p.x() < size * BLOCK_SIZE && p.y() < size * BLOCK_SIZE)
GAME.mouseClick(FLOOR(p.x()), FLOOR(p.y()), m->button() == Qt::RightButton);
//it select the unit
}
...
}
It works well.
Now I want to select several units, so I decided to use the MouseButtonRelease. I save the coord of the point where the mouse is pressed, and when it is released I make a rectangle using the coords of the released point, and I select all the units in this rectangle.
The problem is that the MouseButtonRelease Event is not detected :-/ whereas the Press Event works well...
I don't understand where the problem come from.
I've tested it with that code in my event filter :
Code:
if(event
->type
() == QEvent::MouseButtonPress)
{
qDebug("pressed");
}
else if(event
->type
() == QEvent::MouseButtonRelease)
{
qDebug("released");
}
When I click, for example, 3 times in the map I have in my console :
Code:
>pressed
>pressed
>pressed
And I want to have
Code:
>pressed
>released
>pressed
>released
>pressed
>released
Another problem : I wanted to use the setDragMode(RubberBandDrag) in my MapView to have a nice rectangle, but when I set it, MousePress aren't detected any more :-/
Can someone explain to me what I made wrong ?
Re: No mouseButtonRelease detected
Code:
if(event
->type
() == QEvent::MouseButtonPress)
{
qDebug("pressed");
}
else if(event
->type
() == QEvent::MouseButtonPress)
{
qDebug("released");
}
Unless there's a typo here, you're not testing for the release event.
Re: No mouseButtonRelease detected
Yes there is a typo, my code is :
Code:
if(event
->type
() == QEvent::MouseButtonPress)
{
qDebug("pressed");
}
else if(event
->type
() == QEvent::MouseButtonRelease)
{
qDebug("released");
}
Sorry for that :p
Re: No mouseButtonRelease detected
Maybe it would be advisable to just dump all the event types you receive and see what you get.
Or maybe the release is being filtered out further up the chain before it gets to the widget you are filtering.
Re: No mouseButtonRelease detected
Thank you for you help.
But i finally find another thread where I find how to do
http://www.qtcentre.org/threads/1674...rubberbanddrag
I don't use the event filter, i have reimplement the mouseReleaseEvent() method :)