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. Auto Update Model in QWidgetMapper
Forum Updated to NodeBB v4.3 + New Features

Auto Update Model in QWidgetMapper

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 621 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.
  • H Offline
    H Offline
    hadi_m
    wrote on last edited by hadi_m
    #1

    Hello
    I use QWidgetMapper with a few QlineEdit for editing data in model. when user edit fields in QLineEdit the new data will placed in the model when the enter key( or changing the focus) is pressed. I want to change this behavior so I need the data within the model change on the fly. I mean that data in model change as soon as possible user enter any key without waiting for enter key or changing widget focus.
    Is there any way to accomplish this kind of behavior?

    I want to know everything that I don't know, maybe I don't have enough time for learning all of them but I have a chance to try, and it is enough for me ,so I really appropriate if you learn me anything
    Unknown Programmer

    JonBJ 1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      This is not supported by QDataWidgetMapper, you have to write it by your own.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • H hadi_m

        Hello
        I use QWidgetMapper with a few QlineEdit for editing data in model. when user edit fields in QLineEdit the new data will placed in the model when the enter key( or changing the focus) is pressed. I want to change this behavior so I need the data within the model change on the fly. I mean that data in model change as soon as possible user enter any key without waiting for enter key or changing widget focus.
        Is there any way to accomplish this kind of behavior?

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @hadi_m
        I do this on a widget mapper for a whole bunch of QSpinBoxes. I connect to QSpinBox::valueChanged and the slot calls QDataWidgetMapper::submit() to update the model immediately. It works a treat :)

        Presumably you can do the same against QLineEdit::textEdited. Note that there is a potential little wriggle. If you're not careful, you change the model, it then changes the widget, and then that re-raises the "changed" signal and you get stuck forever. My slot reads the current value from the model and exits if the value passed to the slot is the same as that retrieved from the model. I also use Qt::QueuedConnection to prevent the slot causing changes while still within the original signal call, which was a problem. These may be because I am using QSpinBoxes, may not apply when using QLineEdit::textEdited (which is a different signal from QLineEdit::textChanged which will be emitted when you change the value in the model programmatically and it reflects back to the widget).

        1 Reply Last reply
        2

        • Login

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