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. Reinventing the wheel: qtQuick input widgets
Forum Updated to NodeBB v4.3 + New Features

Reinventing the wheel: qtQuick input widgets

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 1.5k 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.
  • J Offline
    J Offline
    jsprenkle
    wrote on last edited by
    #1

    Good afternoon,

    I'm creating a form to let me edit the content of a database table. I've been looking at the QtQuick TextInput element but it lacks all but the most basic of features. Specifically I'd like:

    • A property that indicates if the user has changed the content of the control
    • A method to pass a type indicator to the control and have it automatically apply the correct validator/input mask. The QVariant type enumeration would be ideal.

    It looks like there's no C++ class to inherit to add this functionality and it's very problematic to use QLineEdit in QML. Any suggestions? I'd much prefer a C++ solution.

    Thanks

    1 Reply Last reply
    0
    • JKSHJ Online
      JKSHJ Online
      JKSH
      Moderators
      wrote on last edited by
      #2

      Hi,

      [quote author="jsprenkle" date="1423081877"]

      • A property that indicates if the user has changed the content of the control
        [/quote]A QML object always emits a signal when a property is changed (see "Property Attributes":http://doc.qt.io/qt-5/qtqml-syntax-objectattributes.html#property-attributes)

      The signal is <property>Changed, and the corresponding signal handler is on<Property>Changed. Example:

      @
      TextInput {
      onTextChanged: console.log("Text changed to" + text)
      }
      @

      In additioin, TextInput provides the accepted() and editingFinished() signals. See http://doc.qt.io/qt-5/qml-qtquick-textinput.html

      [quote author="jsprenkle" date="1423081877"]

      • A method to pass a type indicator to the control and have it automatically apply the correct validator/input mask. The QVariant type enumeration would be ideal.
        [/quote]IMHO, it would be much less effort to check the type in QML and pass the appropriate validator, as opposed to implementing the check in C++

      However, if you really want to do it, you can subclass QQuickItem.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jsprenkle
        wrote on last edited by
        #3

        Thanks for the reply.

        I was surprised that the Qt4 widget version of the input control provides a property that indicates if the input was changed but the qml version does not. It would be used to determine if writing content back to the database was required after the form is dismissed.

        If I subclass QQuickItem then I'll have to reimplement all the keyboard input handling code. I wanted to avoid reinventing the wheel. It's a bit disappointing. I did this in winforms, then vb6, then WPF, and here we are again.

        Maybe I can start with the code from the widget and refactor it to inherit from QQuickItem.

        Thanks again.

        1 Reply Last reply
        0
        • JKSHJ Online
          JKSHJ Online
          JKSH
          Moderators
          wrote on last edited by
          #4

          You're welcome.

          [quote author="jsprenkle" date="1423144212"]I was surprised that the Qt4 widget version of the input control provides a property that indicates if the input was changed but the qml version does not. It would be used to determine if writing content back to the database was required after the form is dismissed.[/quote]You can implement it yourself in two lines:

          @
          TextInput {
          property bool isModified: false
          onTextChanged: isModified = true
          }
          @

          To unset the flag, just call isModified = false

          [quote author="jsprenkle" date="1423144212"]Maybe I can start with the code from the widget and refactor it to inherit from QQuickItem.[/quote]I recommend implementing it in QML. It's much less effort.

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          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