Results 1 to 7 of 7

Thread: Catching Mouse Events on Top-Level Window

  1. #1
    Join Date
    Aug 2009
    Location
    Lancashire UK
    Posts
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question Catching Mouse Events on Top-Level Window

    Is there any way of catching Mouse events (principally Press and Release) for the window frame of a QMainWindow. I need to compress moveEvents and resizeEvents for the window, because I want to suppress the "show contents while dragging" behavior (Windows,Linux and Mac). Overriding the mousePressEvent and mouseReleaseEvent handlers on a class derived from QMainWindow doesn't give me mouse events on the window frame, but only in the client area of the window.

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Catching Mouse Events on Top-Level Window

    Window frame is managed by the OS...you only get
    Qt Code:
    1. QWidget::moveEvent
    To copy to clipboard, switch view to plain text mode 
    when u press and move the window frame.

    I am afraid you might not get press and release event for the frame( I assume the top blue frame in windows).

    By the way what do u need from press and release of the frame ? Might be there is some other way to achieve your goal...

  3. #3
    Join Date
    Aug 2009
    Location
    Lancashire UK
    Posts
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Catching Mouse Events on Top-Level Window

    My problem is that some of my windows have complex contents, therefore they take quite a time to repaint, which of course I can only do in the GUI thread. Currrently every move/resize event is generating a repaint. I need to compress the move/resize events so that I only do a full redraw on the "last" one, i.e. the event on mouse button up. Then I need only repaint my complex windows once. This is easy on Win32 because you can catch "window moving" and mouse events on the window frame, but alas not in QT that I can find.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Catching Mouse Events on Top-Level Window

    You can intercept moveEvent and resizeEvent and block updates for that perdion. Then after some time (using a timer) you can enable updates back and schedule an update.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Aug 2009
    Location
    Lancashire UK
    Posts
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Catching Mouse Events on Top-Level Window

    Thanks for the advice. However the updates issue is not really the solution I feel since the repaints are not handled automatically but controlled by another thread. I just need to catch the last "resize" (or "move") event because this changes characteristics of the window and thus what gets repainted therein. At that point I then force an update if necessary. The problem, which I know you understand, is that I am getting one of these on every mouse move which eventually locks the thing up. A timer is probably the answer, but I just thought any way of catching the mouse-up event would do me.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Catching Mouse Events on Top-Level Window

    Quote Originally Posted by andyp View Post
    However the updates issue is not really the solution I feel since the repaints are not handled automatically but controlled by another thread.
    Hmm? How come? Are you sure this is safe?

    I just need to catch the last "resize" (or "move") event because this changes characteristics of the window and thus what gets repainted therein. At that point I then force an update if necessary.
    My solution remains valid. Start a timer on first move or resize, if another move or resize happens before the timer fires, restart it. When the timer fires it is safe to assume the window has already been put in its final position.

    The problem, which I know you understand, is that I am getting one of these on every mouse move which eventually locks the thing up. A timer is probably the answer, but I just thought any way of catching the mouse-up event would do me.
    I can move the window without touching the mouse and then what?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Aug 2009
    Location
    Lancashire UK
    Posts
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Catching Mouse Events on Top-Level Window

    By jove you're right Caruthers.
    When I said "controlled by another thread" I meant controlled, not painted. It is thread-safe. It is a real pain that you can't make window (X) calls from threads other than the GUI thread. I can see why they (QT) have "copped out" this way, it has saved them making a threadsafe X system with a multitude of "critical sections" etc.
    Back to the resize/move events: yes, your way is a good solution. I was just not sure of the overhead involved in restarting a timer on every move/resize event. I shall run it up the flagpole. Mille grazie. It is of course arbitrary what length of time is chosen, also if they hold the button down for ages while moving/resizing this may mean we get an extra event or two, but that is bearable compared to the current locks ups.

Similar Threads

  1. How to get mouse click events outside the Qt window?
    By montylee in forum Qt Programming
    Replies: 11
    Last Post: 13th July 2015, 22:55
  2. QGraphicsView Mouse Events
    By tomf in forum Qt Programming
    Replies: 5
    Last Post: 29th July 2008, 16:03
  3. mouse moving don't produce mouse events
    By coralbird in forum Qt Programming
    Replies: 1
    Last Post: 13th September 2006, 07:13
  4. Replies: 2
    Last Post: 24th July 2006, 19:36
  5. QStackerWidget and mouse events
    By high_flyer in forum Qt Programming
    Replies: 3
    Last Post: 25th April 2006, 20:25

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.