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. Qt:Focus::NoFocus still takes focus
Qt 6.11 is out! See what's new in the release blog

Qt:Focus::NoFocus still takes focus

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 2.2k Views 1 Watching
  • 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.
  • E Offline
    E Offline
    EdwardWu
    wrote on last edited by
    #1

    I have a keyboard widget that appears when an EditText is focused. I want it to disappear when anywhere other than the EditText is clicked. So I set,

    mainWindow().setFocusPolicy(Qt::StrongFocus);
    

    But, when I click on the Qframe that holds the keyboard, it disappears even though I've set the QFrame to Qt::NoFocus.

    <widget class="QFrame" name="keyboardFrame">
     <property name="focusPolicy">
       <enum>Qt::NoFocus</enum>
      </property>
    </widget>
    

    I've tried a different approach where I set the parent to Qt::StrongFocus and it's child to Qt:NoFocus, but it seems that the parent Qt::StrongFocus still propagates to its child. Any help would be much appreciated. Thanks!

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Not sure why no focus is ignored. Normally it's not.
      Anyway, try to hook a slot to
      https://doc.qt.io/qt-5/qapplication.html#focusChanged
      and check what it changes to so we are sure it is the
      QFrame that is guilty.

      1 Reply Last reply
      0
      • E Offline
        E Offline
        EdwardWu
        wrote on last edited by
        #3

        Seems like the mainWindow is getting the focus. So, I set the frame to StrongFocus and I can later handle it to keep the keyboard up. However, now, if I have two Qt::StrongFocus objects, mainWindow & QFrame, the mainWindow gets the focus even if the frame is on top. Any way I can change it so the QFrame receives the focus?

        1 Reply Last reply
        0

        • Login

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