PDA

View Full Version : Problems after changing flags to a QWidget



PinTxO
27th February 2018, 11:25
Hi guys.
I have a QWidget as the child of another within my application. The task consists of putting the internal widget in full screen mode and being able to see it again in normal mode with the same button. This partly I have managed to do it in the following way:


if(!isFullScreen())
{
setWindowFlags(windowFlags() | Qt::Window);
showFullScreen();
}
else
{
setWindowFlags(windowFlags() & ~Qt::Window);
showNormal();
activateWindow();
}
The problem arises when you return to see the widget in normal mode. Things that happen:


The mouse cursor stays with pointing hand cursor.
The button to change mode remains in hover state (the background color is changed when the mouse is over).
Passing the mouse through other widget controls does not change its appearance.



I have to click on the widget to fix the behavior. It's as if the widget did not receive events of any kind or something like that. I tried calling setFocus () and it did not work. I have also tried to send an event by hand in the following way but it has not worked either:


QMouseEvent my_event(QEvent::MouseButtonPress, QPointF (0, 0), Qt :: NoButton, 0, 0);
QApplication::sendEvent(this, & my_event);
Any ideas?

Thanks.

high_flyer
27th February 2018, 14:21
I am actually surprised this works for you as well as it does, I would not expect it.
The reason being that you have a parented widget (not only in the sense of hierarchy but also in the visual sense).
I wonder what the windowing system is doing when your widget goes to full screen mode - does it detach it from its parent (visually) and out of a layout it is in?
If so, how does it know where to return it to...?
I wonder if what you are doing is a misuse of the full screen functionality in that sense.

In your place I would not have implemented it like that probably.
I would pop up a new full screen widget which would have been cloned from the parented one.
Makes everything much simpler and cleaner IMHO.