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. How Best to Prevent Focus Leaving a Widget?
QtWS25 Last Chance

How Best to Prevent Focus Leaving a Widget?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt 5.7desktop
5 Posts 5 Posters 4.5k 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.
  • G Offline
    G Offline
    GBWarren
    wrote on last edited by
    #1

    I have a need within a given Qt window (main and dock) to validate data that has been entered in a field-type widget (QLineEdit typically), and not allow the keyboard focus to move to a different widget in the same window when the data is invalid. There are informational events for the widgets involved in the focus transfer, but not a way to directly block the focus out (event).

    Does anyone have a suggestion for what the best way to do this is?

    P 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      In that case shouldn't you use a modal QDialog to ensure your user can't do anything you don't want while the input is wrong ?

      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
      2
      • A Offline
        A Offline
        Asperamanca
        wrote on last edited by
        #3

        I suggest exploring alternatives also:

        • Mark fields with invalid values and disable "apply" "ok" and similar controls until all invalid values are corrected

        • Revert to the last known good value if the user leaves a field with an invalid value in it

        • Prevent entering an invalid value by restricting what users can type

        1 Reply Last reply
        2
        • J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          You could go and set all other widgets to disabled

          void QWidget::setDisabled(bool disable)
          

          convenient enough, if you have a good Layouttree


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          1
          • G GBWarren

            I have a need within a given Qt window (main and dock) to validate data that has been entered in a field-type widget (QLineEdit typically), and not allow the keyboard focus to move to a different widget in the same window when the data is invalid. There are informational events for the widgets involved in the focus transfer, but not a way to directly block the focus out (event).

            Does anyone have a suggestion for what the best way to do this is?

            P Offline
            P Offline
            pr1321
            wrote on last edited by
            #5

            https://forum.qt.io/topic/114575/focus-transmission-rejecting

            1 Reply Last reply
            1

            • Login

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