Blocking Child Widgets of Widget
-
Lets say I have a Widget which contains several Child Widgets in a layout.
In the beginning I can interact with the Child Widgets . (e.g click on a Child Widgets changes there appearance),
At some point I want to prevent that any events get send to the Child Widgets . So disable all possible interactions with the Child Widgets.
Whats the easiest way to achieve that?
I thought about installing an event filter into the Widget or adding a disable flag in the Child Widget which disables watching the events which is called by the Widget.
-
It's not clear which events you want to block. There are a lot and blocking some of them will break your widgets, for example not handling resize event or focus events will break the look/ control flow. Not handling the paint event will break the look. There are a lot of event types. Disabling all of them is basically like hiding the widget entirely.
Depending on what the child widgets actually are there are couple of things you could do. If you just want to disable user's interaction with these widgets there's setDisabled().
Some widgets, like the ones handling text have a readOnly property.
Some other widgets only handle user input when they have focus so you can change their focusPolicy toQt::NoFocus
.
If you want to go lower level you can ignore user input by setting the window flagQt::WindowTransparentForInput
totrue
.There are probably more things you can do but you need to be more specific on what you actually want to accomplish.
-
The Childs are directly derrived from QWidget and have some interactions from mouse click events.
I want to block the evaluation of these, when the parent of them reaches a certain condition.
-
Then, like I said, you can disable those widgets and check isEnabled() in your mouse handler code or set that
Qt::WindowTransparentForInput
flag which will pass the events directly to whatever is under your widget. -
i tryed
setWindowFlag(Qt::WindowTransparentForInput);
however mouse events still get passed to the childs -
i tryed
setWindowFlag(Qt::WindowTransparentForInput);
however mouse events still get passed to the childs@sandro4912 said in Blocking Child Widgets of Widget:
i tryed setWindowFlag(Qt::WindowTransparentForInput); however mouse events still get passed to the childs
Ah, sorry, my mistake.
Qt::WindowTransparentForInput
is for windows (top level widgets). For regular children the equivalent iswidget->setAttribute(Qt::WA_TransparentForMouseEvents);
-
That works. I think is a better solution than iterating over all the childs and set Enabled to false;
-
That works. I think is a better solution than iterating over all the childs and set Enabled to false;
@sandro4912 said in Blocking Child Widgets of Widget:
That works.
Is your issue solved then? If so, please don't forget to mark your post as such! Thanks