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. Can't set focus to TextInput placed in contextItem, when ComboBox popup is opened.
Forum Updated to NodeBB v4.3 + New Features

Can't set focus to TextInput placed in contextItem, when ComboBox popup is opened.

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 464 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.
  • V Offline
    V Offline
    Vaclav
    wrote on last edited by
    #1

    Hello everyone,
    I have problem with ComboBox customization. I can't set focus to TextInput placed in contextItem, when ComboBox popup is opened. Opened popup disable all events from keyboard, mouse etc. and there is no possibility to write text into TextInput. Here is my code:

    import QtQuick 2.12
    import QtQuick.Window 2.12
    import QtQuick.Controls 2.12
    import QtQml 2.3
    ComboBox {
            id: cbx
            Component {
                id: textNotEditable
                Text {
                    text: cbx.currentText
                    horizontalAlignment: Text.AlignLeft
                    verticalAlignment: Text.AlignVCenter
                }
            }
            Component {
                id: textInputEditable
                TextInput {
                    text: "aaa"
                    horizontalAlignment: Text.AlignLeft
                    verticalAlignment: Text.AlignVCenter
                }
            }
            contentItem: Loader {
                sourceComponent: cbx.popup.visible ? textInputEditable : textNotEditable
            }
            model: ListModel {
                id: model
                ListElement { text: "Banana" }
                ListElement { text: "Apple" }
                ListElement { text: "Coconut" }
            }
        }
    
    

    bb5a8697-2691-4efc-bd0d-80ec2c6884a2-image.png

    Do You have any idea how to set focus to TextInput or bridge event filtering when popup is opened?
    Thank You for Your help.
    Vaclav.

    1 Reply Last reply
    0
    • Diego MoralesD Offline
      Diego MoralesD Offline
      Diego Morales
      wrote on last edited by
      #2

      Hi,

      I tested you code and the problem was you were missing the editable property (https://doc.qt.io/qt-5/qml-qtquick-controls2-combobox.html#editable-prop). With the two components it will work, but I think with one component it is simply, here is the code with a couple of changes:

      import QtQuick 2.12
      import QtQuick.Window 2.12
      import QtQuick.Controls 2.12
      import QtQml 2.3
      ComboBox {
      id: cbx
      editable: true
      Component {
      id: textInputEditable
      TextInput {
      readOnly: !cbx.popup.visible
      text: readOnly ? cbx.currentText : "aaa"
      horizontalAlignment: Text.AlignLeft
      verticalAlignment: Text.AlignVCenter
      }
      }
      contentItem: Loader {
      sourceComponent: textInputEditable
      }
      model: ListModel {
      id: model
      ListElement { text: "Banana" }
      ListElement { text: "Apple" }
      ListElement { text: "Coconut" }
      }
      }
      Also I found this https://forum.qt.io/topic/91051/dynamically-override-contentitem-of-a-combobox/4, maybe can help you.

      Regards.

      --
      Lic-Ing. Luis Diego Morales Alfaro
      Embedded Software Engineer
      RidgeRun Engineering Ltd.
      www.ridgerun.com
      diego.morales@ridgerun.com

      1 Reply Last reply
      0
      • V Offline
        V Offline
        Vaclav
        wrote on last edited by
        #3

        Now it works. Thanks a lot.
        Vaclav.

        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