Disabling user keyboard input to single widget and it's children
-
Hello,
I'm working on a widget spesific loading view, during which the widget should not accept any user inputs from the keyboard. This widget class is a base for most of my applications widgets.
Now, I need a way to disable keyboard inputs the widget and it's children. For example, I might have a widget which has a QLineEdit object, and when the loading view is activated, any keyboard inputs to this widget should be ignored.
I know I can just set QWidget::setDisabled(true), and I will go for that if necessary... But is there any other way? Disabling the widget causes some minor graphical problems for my widgets (won't go to detail for now).
I've tried to implement a keyPressEvent and eventFilter, where the keypress event is ignored, if the loading view has been activated:
@
if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease)
{
if (this->loading_view != NULL)
{
if (this->loading_view->isVisible())
{
event->ignore();
return true;
}
}
}
@But the event is still passed to the QLineEdit aswell, which has focus. I also know I could use grabKeyboard -function, but I don't want to ignore every keyboard input application wide, just for this one widget which has it's loading view active.
-
"setFocusPolicy":http://qt-project.org/doc/qt-5/qwidget.html#focusPolicy-prop may help here. But I'm not sure.
-
Install filter should do the magic for you. Where did you install the filter ? Did you install the filter for the lineEdit ? You can try grabKeyboard as well
-
Hi,
Just from a user point of view, having an enabled widget not reacting on user input will be counter intuitive and people might think that there's a bug.
You can either disable the widgets or maybe use a modal dialog.
Hope it helps
-
[quote author="SGaist" date="1407620276"]Hi,
Just from a user point of view, having an enabled widget not reacting on user input will be counter intuitive and people might think that there's a bug.
You can either disable the widgets or maybe use a modal dialog.
Hope it helps[/quote]
If the input is blocked, there wil be an overlay widget visible to the user. Basically the user can't even see the input field, but if it had focus or the user manages to tab focus the widget underneath the loading view (I use a kind of overlay widget), the user would be able to give input to the widget.
Using a modal dialog might be something to try, as I remeber it doesn't always have to application wide modal? I'll give it a try, thanks!
-
Indeed, a dialog can also be window modal