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. how to detect if all child items have focus set to "false" within an item?
Forum Updated to NodeBB v4.3 + New Features

how to detect if all child items have focus set to "false" within an item?

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

    i have a parent qml called ,

    Rectangle
    {
    id: main
    Item
    {
    id: item1
    }
    Item
    {
    id: item2
    }
    Item
    {
    focus: true
    id: item3
    }
    }

    item1 and item2 contains TextField as child item which receives focus on clicking the item.
    when i launch for first time item3 has focus set to true , but when i click any other item1 or itme2 it looses focus as text field inside item2 or item3 takes the focus.
    now when i close item2 or item3 their children loose focus. at this moment none of the items have focus. so i would want to go set item3 focus to true .
    so basically i want to know when none of the child items in "main" rectangle have focus so that i can set "item3" focus true.

    J.HilkJ 1 Reply Last reply
    0
    • A AYYAPPA

      i have a parent qml called ,

      Rectangle
      {
      id: main
      Item
      {
      id: item1
      }
      Item
      {
      id: item2
      }
      Item
      {
      focus: true
      id: item3
      }
      }

      item1 and item2 contains TextField as child item which receives focus on clicking the item.
      when i launch for first time item3 has focus set to true , but when i click any other item1 or itme2 it looses focus as text field inside item2 or item3 takes the focus.
      now when i close item2 or item3 their children loose focus. at this moment none of the items have focus. so i would want to go set item3 focus to true .
      so basically i want to know when none of the child items in "main" rectangle have focus so that i can set "item3" focus true.

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      Hi @AYYAPPA

      this should work.

      Rectangle
      {
          property bool noActiveFocus: !item1.activeFocus && !item2.activeFocus && !item3.activeFocus
          onNoActiveFocusChanged: if(noActiveFocus) item3.focus = true
      
          id: main
          Item{
               id: item1
          }
      
          Item{
              id: item2
          }
      
          Item{
              focus: true
              id: item3
         }
      }
      

      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
      0

      • Login

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