Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Disabling user keyboard input to single widget and it's children
QtWS25 Last Chance

Disabling user keyboard input to single widget and it's children

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 4.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    Zerby
    wrote on 8 Aug 2014, 19:58 last edited by
    #1

    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.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on 8 Aug 2014, 22:33 last edited by
      #2

      "setFocusPolicy":http://qt-project.org/doc/qt-5/qwidget.html#focusPolicy-prop may help here. But I'm not sure.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dheerendra
        Qt Champions 2022
        wrote on 9 Aug 2014, 00:19 last edited by
        #3

        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

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 9 Aug 2014, 21:37 last edited by
          #4

          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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            Zerby
            wrote on 11 Aug 2014, 18:29 last edited by
            #5

            [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!

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 11 Aug 2014, 21:16 last edited by
              #6

              Indeed, a dialog can also be window modal

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              2/6

              8 Aug 2014, 22:33

              topic:navigator.unread, 4
              • Login

              • Login or register to search.
              2 out of 6
              • First post
                2/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved