Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Stop Button from stealing focus

Stop Button from stealing focus

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 1 Posters 5.8k 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.
  • D Offline
    D Offline
    davidljung
    wrote on last edited by
    #1

    Hello.
    I can't figure out how to avoid buttons stealing focus in QML/QtQuick.
    For example, suppose (simplified case) I have a TextField and a Button (Qt Quick Controls 2). Initially the TextField is focused for entry. Then, when the button is clicked, I do not want to remove focus from the TextField.

    How can stop the focus from changing when the Button is clicked?
    I understood that setting focus: true requests focus, but setting it to false doesn't seem to stop focusing. I've tried to set it back to false on onActiveFocusChanged to no avail. Also, wrapping the Button in a FocusScope with focus: false doesn't have any effect either: clicking the button still unfocuses the TextField.

    Appreciate any insight into how to solve the problem.
    Thanks!

    (PS: In the actual application, any of many controls in the UI could have focus when the button is clicked and I'd like not to steal the focus from whichever is focused. Hence, solutions requiring keeping track of what is focused somehow are less desirable)

    1 Reply Last reply
    2
    • D Offline
      D Offline
      davidljung
      wrote on last edited by
      #2

      To answer my own question :)

      Just add:
      focusPolicy: Qt.NoFocus
      to the Button and the behaviour is as desired!

      1 Reply Last reply
      2

      • Login

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