Results 1 to 2 of 2

Thread: enterEvent, leaveEvent, setWindowFlags

  1. #1
    Join Date
    Jan 2006
    Location
    Munich, Germany.
    Posts
    111
    Thanks
    29
    Thanked 3 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default enterEvent, leaveEvent, setWindowFlags

    I know this is maybe silly, but I have a widget which should only show its borders (WindowSystemMenuHint;//only a close button) when entered. The user should then be able to use the title bar to move the widget (or close it). However, when the user moves the mouse away from the widget, the border should disappear.

    sounds easy, doesn't it - just re-implemented the enter and leave events!
    Here's my attempt:
    Qt Code:
    1. void BuddyFramedLabel::enterEvent (QEvent* event)
    2. {
    3. Qt::WindowFlags flags = 0;
    4. flags = Qt::Window;//normal window
    5.  
    6. //need to show the window frame
    7. flags |= Qt::WindowSystemMenuHint;//only a close button
    8. setWindowFlags(flags);
    9.  
    10. QWidget::show();//need this, otherwise the widget disappears!
    11. }
    12. void BuddyFramedLabel::leaveEvent (QEvent* event)
    13. {
    14. Qt::WindowFlags flags = 0;
    15. flags = Qt::Window;//normal window
    16.  
    17. //need to hide the window frame
    18. flags |= Qt::FramelessWindowHint;//Qt::Tool;
    19. setWindowFlags(flags);
    20.  
    21. QWidget::show();//need this, otherwise the widget disappears!
    22. }
    To copy to clipboard, switch view to plain text mode 

    The problem as soon as you want to use the title bar, you leave the widget and the title bar disappears.
    So, is there a leaveEvent() or something similar for a whole window (incl. title bars)?
    Any other solution would also be greatly appreciated. I'm sure there's something obvious.
    thanks
    K

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: enterEvent, leaveEvent, setWindowFlags

    Sorry, but I think this is beyond the scope of Qt. Qt doesn't provide or handle the window decoration. Qt can only give certain hints to the underlying system.

    The problem is that the widget should monitor mouse events until the mouse leaves the window frames. Grabbing the mouse is the only way of receiving mouse events outside a widget (the window frames are outside the widget).

    One could try to grab the mouse in the leave event handler and then compare the mouse position to the frame geometry in the mouse move event handler and release it as soon as it gets outside the window frames. However, grabbing the mouse would prevent the user of interacting with the window frames, including the title bar and it's buttons.

    So, as a conclusion I'd say the easier approach might be to use a frameless window and provide your own custom fancy window decoration. This will require handling of window movement and such by your own, though.
    J-P Nurmi

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.