PDA

View Full Version : enterEvent, leaveEvent, setWindowFlags



TheKedge
2nd February 2007, 15:38
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:


void BuddyFramedLabel::enterEvent (QEvent* event)
{
Qt::WindowFlags flags = 0;
flags = Qt::Window;//normal window

//need to show the window frame
flags |= Qt::WindowSystemMenuHint;//only a close button
setWindowFlags(flags);

QWidget::show();//need this, otherwise the widget disappears!
}
void BuddyFramedLabel::leaveEvent (QEvent* event)
{
Qt::WindowFlags flags = 0;
flags = Qt::Window;//normal window

//need to hide the window frame
flags |= Qt::FramelessWindowHint;//Qt::Tool;
setWindowFlags(flags);

QWidget::show();//need this, otherwise the widget disappears!
}

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

jpn
3rd February 2007, 09:15
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.