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. [Solved] Check which child has the focus in the Column element
Qt 6.11 is out! See what's new in the release blog

[Solved] Check which child has the focus in the Column element

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 2 Posters 5.0k 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
    ephe
    wrote on last edited by
    #1

    I've checked which child has the focus in the Column element like this:

    @
    for(var i = 0; i < column.children.length; i++)
    {
    if(column.children[i].activeFocus)
    {
    ...
    }
    }
    @

    Is there a better way to check it?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Send signal from children when they get focus. Or use GridView, it has focus handling built-in.

      (Z(:^

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

        Thank you very much for your answer!

        I've got a special focus handling. E.g. when enter is pressed, the focus should be on the textfield of the rectangle and when enter is pressed again, it should move to the next item in the column.

        Grid view would need a model. I'm adding the items to the column in C++, so I think it is easier to handle everything in the column, but maybe I'm wrong and just thinking too complicated.

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          It's your choice, obviously. Column is easier, GridView has more features. There is a way to use GridView without a real model. I'll give you an example (copy-paste from live code, so some variables could be hard to understand. Also, it uses JS, not C++):
          @
          function populateUnits(tmpUnitsList) {
          unitsList = tmpUnitsList;

              for (var i = 0; i < unitsList.length; i++) {
                  var currentUnit = unitsList[i];
                  unitModel.append({"unitType": currentUnit.unitType,
                                       "unitLogo": currentUnit.unitLogo,
                                       "unitStatus": currentUnit.unitStatus,
                                       "unitSelected": currentUnit.selected});
                  currentUnit.unitStatusChanged.connect(changeStatus);
                  currentUnit.selectionChanged.connect(selectionChanged);
              }
          }
          
          ListModel {
              id: unitModel
          }
          
          Component {
              id: unitDelegate
          
              RosterMenuEntry {
                  backgroundColor: root.backgroundColor
          
                  entryText: unitType
                  entryLogo: unitLogo
                  entryStatusText: unitStatus
                  selected: unitSelected
              }
          }
          
          GridView {
              id: units
              anchors.topMargin: 2
              anchors.leftMargin: 2
              interactive: false
          
              anchors.top: parent.top
              anchors.left: parent.left
          
              height: (cellHeight * 4) + 3
              width: (cellWidth) + 3
              flow: GridView.TopToBottom // This means it will act as a Column
          
              model: unitModel
              delegate: unitDelegate
          }
          

          @

          (Z(:^

          1 Reply Last reply
          0
          • sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #5

            So, I start with an empty model, and then add elements with my populateUnits() function. ListModel::append is used here. It's well documented in Qt docs.

            (Z(:^

            1 Reply Last reply
            0
            • E Offline
              E Offline
              ephe
              wrote on last edited by
              #6

              Thank you, I've done that for other objects which I wanted to display in a list.
              But I don't know if I can fill a GridView with different self-made components like a textfield, checkbox,... in the column, this is working fine.

              I have seen the VisualItemModel, but I think it is not possible to fill this in C++.

              1 Reply Last reply
              0
              • sierdzioS Offline
                sierdzioS Offline
                sierdzio
                Moderators
                wrote on last edited by
                #7

                Could probably be done with Loader as a model - but that seems to be an overkill.

                (Z(:^

                1 Reply Last reply
                0
                • E Offline
                  E Offline
                  ephe
                  wrote on last edited by
                  #8

                  Probably it is.
                  But thank you very much anyway! I'm sure that I can use your information somewhere else.

                  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