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. ComboBox text reset on model update
Forum Updated to NodeBB v4.3 + New Features

ComboBox text reset on model update

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

    Hello! As far as I understand, in ComboBox every time model gets updated from C++, the text in editable Text Edit gets erased. Is there a way to update model without resetting text? And also, is there a way to have a dropdown list opened and being able to write in text edit?

    J.HilkJ 1 Reply Last reply
    0
    • I Imynn

      Hello! As far as I understand, in ComboBox every time model gets updated from C++, the text in editable Text Edit gets erased. Is there a way to update model without resetting text? And also, is there a way to have a dropdown list opened and being able to write in text edit?

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

      hi @Imynnand welcome

      Is there a way to update model without resetting text?

      possibly this:

       ComboBox{
              id:myCombobox
              anchors{
                  left: parent.left
                  right: parent.right
                  top: parent.top
              }
              height: 50
      
              editable: true
      
      
              Binding{
                  target: myCombobox
                  property: "model"
                  value: root.count
                  when: !myCombobox.activeFocus
              }
          }
      
          property int count: 1
      
          Timer{
              id:changeModel
              running: true
              interval: 1000
              repeat: true
              onTriggered: count++
          }
      

      And also, is there a way to have a dropdown list opened and being able to write in text edit

      you probably will have to overwrite the popup component of the combox to modify that behaviour


      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
      • I Offline
        I Offline
        Imynn
        wrote on last edited by Imynn
        #3

        @J-Hilk Thank you for your reply! I can see that this binding adds something to model. But what if I type something in text edit, and in my C++ code the model gets reset. For example, I have TextField in ComboBox

        TextField {
            text: root.editText
            onTextChanged: {
                updateModel() 
            }
        
        void CustomModel::updateModel()
        {
            beginResetModel();
            endResetModel();
        }
        

        But whenever it happens, text in text edit gets erased. So for example. I write one letter in text edit, model gets updated, then I type another letter, and the text gets erased. The most interesting thing is that text that I typed gets erased every second attempt to write something. And if there was some text before it remains unchanged, only my input is affected. Any ideas why it happens? Thank you

        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