Results 1 to 5 of 5

Thread: No mouseButtonRelease detected

Threaded View

Previous Post Previous Post   Next Post Next Post
  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 17:44.

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, 10:18
  2. Recursive call detected
    By SebastianBecker in forum Qt Programming
    Replies: 3
    Last Post: 10th September 2009, 17:25
  3. glibc detected
    By raghvendramisra in forum Qt Programming
    Replies: 5
    Last Post: 28th May 2008, 03:29
  4. Error: **** glibc detected ****
    By Manohar in forum Qt Programming
    Replies: 2
    Last Post: 9th May 2008, 05:32
  5. no MouseButtonRelease event for QComboBox
    By Beluvius in forum Qt Programming
    Replies: 5
    Last Post: 31st March 2006, 12: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.