Results 1 to 5 of 5

Thread: No mouseButtonRelease detected

  1. #1
    Join Date
    Sep 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question 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 :
    Qt Code:
    1. #include <QGraphicsView>
    2.  
    3.  
    4.  
    5.  
    6.  
    7.  
    8. namespace Interface
    9.  
    10. {
    11.  
    12. class MainWindow;
    13.  
    14.  
    15.  
    16. class WarMapView : public QGraphicsView
    17.  
    18. {
    19.  
    20. protected:
    21.  
    22. MainWindow* window;
    23.  
    24. bool eventFilter(QObject *obj, QEvent *event);
    25.  
    26.  
    27.  
    28. public:
    29.  
    30. WarMapView(QGraphicsScene* scene, MainWindow* parent = 0);
    31.  
    32. void update();
    33.  
    34. };
    35.  
    36. }
    To copy to clipboard, switch view to plain text mode 

    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 :

    Qt Code:
    1. bool WarMapView::eventFilter(QObject *obj, QEvent *event)
    2.  
    3. {
    4.  
    5. if(event->type() == QEvent::MouseButtonPress)
    6.  
    7. {
    8.  
    9. QMouseEvent* m = dynamic_cast<QMouseEvent*>(event);
    10.  
    11. QPointF p = mapToScene(mapFromParent(m->pos()));
    12.  
    13.  
    14.  
    15. // if in the map
    16.  
    17. int size = GAME.getMap().getSize();
    18.  
    19. if(p.x() >= 0 && p.y() >= 0 && p.x() < size * BLOCK_SIZE && p.y() < size * BLOCK_SIZE)
    20.  
    21. GAME.mouseClick(FLOOR(p.x()), FLOOR(p.y()), m->button() == Qt::RightButton);
    22. //it select the unit
    23. }
    24. ...
    25. }
    To copy to clipboard, switch view to plain text mode 

    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 :

    Qt Code:
    1. if(event->type() == QEvent::MouseButtonPress)
    2.  
    3. {
    4.  
    5. qDebug("pressed");
    6.  
    7. }
    8.  
    9. else if(event->type() == QEvent::MouseButtonRelease)
    10.  
    11. {
    12.  
    13. qDebug("released");
    14.  
    15. }
    To copy to clipboard, switch view to plain text mode 

    When I click, for example, 3 times in the map I have in my console :

    Qt Code:
    1. >pressed
    2. >pressed
    3. >pressed
    To copy to clipboard, switch view to plain text mode 

    And I want to have

    Qt Code:
    1. >pressed
    2. >released
    3. >pressed
    4. >released
    5. >pressed
    6. >released
    To copy to clipboard, switch view to plain text mode 

    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 ?
    Last edited by maitrezeta; 2nd September 2010 at 18:44.

  2. #2
    Join Date
    Jul 2010
    Posts
    21
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: No mouseButtonRelease detected

    Qt Code:
    1. if(event->type() == QEvent::MouseButtonPress)
    2.  
    3. {
    4.  
    5. qDebug("pressed");
    6.  
    7. }
    8.  
    9. else if(event->type() == QEvent::MouseButtonPress)
    10.  
    11. {
    12.  
    13. qDebug("released");
    14.  
    15. }
    To copy to clipboard, switch view to plain text mode 

    Unless there's a typo here, you're not testing for the release event.

  3. #3
    Join Date
    Sep 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: No mouseButtonRelease detected

    Yes there is a typo, my code is :

    Qt Code:
    1. if(event->type() == QEvent::MouseButtonPress)
    2.  
    3. {
    4.  
    5. qDebug("pressed");
    6.  
    7. }
    8.  
    9. else if(event->type() == QEvent::MouseButtonRelease)
    10.  
    11. {
    12.  
    13. qDebug("released");
    14.  
    15. }
    To copy to clipboard, switch view to plain text mode 

    Sorry for that

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.

  5. #5
    Join Date
    Sep 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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

Similar Threads

  1. QT in Path not Detected - On Ubuntu 9.10
    By prchakal in forum Installation and Deployment
    Replies: 1
    Last Post: 9th March 2010, 11:18
  2. Recursive call detected
    By SebastianBecker in forum Qt Programming
    Replies: 3
    Last Post: 10th September 2009, 18:25
  3. glibc detected
    By raghvendramisra in forum Qt Programming
    Replies: 5
    Last Post: 28th May 2008, 04:29
  4. Error: **** glibc detected ****
    By Manohar in forum Qt Programming
    Replies: 2
    Last Post: 9th May 2008, 06:32
  5. no MouseButtonRelease event for QComboBox
    By Beluvius in forum Qt Programming
    Replies: 5
    Last Post: 31st March 2006, 13:58

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.