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. Tracking when focus leaves a TextField

Tracking when focus leaves a TextField

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 3.1k 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.
  • P Offline
    P Offline
    pavneetarora
    wrote on last edited by
    #1

    This is a quick note on how I ended up solving the problem I outlined earlier in this "thread":http://qt-project.org/forums/viewthread/15444/. I am not entirely happy with the solution, but in case someone else comes down the same path looking for a solution, at least it is one possible way of doing it.

    The problem definition is this: I want to be notified when the user leaves a field, presumably after editing it. The page displays a parametric equation so that the other fields may then be computed based on the modified value.

    In my TextField definition, I do the following:

    @
    TextField {
    id: x
    onActiveFocusChanged: {calcXYObject.toggleExitingField();
    calcXYObject.setX(x.text)}
    }
    @

    In my CalcXY C++ class, I put this in the setX (and setY and setZ) members:

    @
    if (exitingField && (newX != x)) {
    x=newX
    }
    @

    where exitingField is a private variable that toggles with every focus change.

    As I said, I don't like it, and I hope that there is a better way but this allows me to get something in place until I find a better solution. Ideally, there should be an onExitField event that we can trap.

    Regards.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dridk
      wrote on last edited by
      #2

      You should use Qt Property System !
      exemple :
      @
      Field {
      value: calcXYObject.valueA
      onActiveFocusChanged: calcXYObject.reset()
      }

      Field {
      value: calcXYObject.valueB
      onActiveFocusChanged: calcXYObject.reset()
      }

      Field {
      value: calcXYObject.valueC
      onActiveFocusChanged: calcXYObject.reset()
      }

      //================ IN CPP

      void CalcXYObject::reset()
      {

      valueA = .....
      valueB = ......
      valueC = ......

      emit valueAChanged();
      emit valueBChanged();
      emit valueCChanged();

      }

      //==================== IN H

      class CalcXYObject : public QObject
      {
      Q_PROPERTY(int valueA READ getValueA WRITE setValueA NOTIFY valueAChanged)
      Q_PROPERTY(int valueB READ getValueB WRITE setValueA NOTIFY valueBChanged)
      Q_PROPERTY(int valueA READ getValueC WRITE setValueC NOTIFY valueCChanged)

      void getValueA(){return mValueA;}
      void getValueB(){return mValueB;}
      void getValueC(){return mValueC;}

      void setValueA(int val){mValueA = val;}
      void setValueB(int val){mValueB = val;}
      void setValueC(int val){mValueC = val;}

      signals:
      void valueAChanged();
      void valueBChanged();
      void valueCChanged();

      }

      @

      Nothing in Biology Makes Sense Except in the Light of Evolution

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pavneetarora
        wrote on last edited by
        #3

        Thanks!

        I'll give this a try. Makes more sense.

        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