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. TextInput & MouseArea
Forum Updated to NodeBB v4.3 + New Features

TextInput & MouseArea

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 7 Posters 9.8k 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.
  • C Offline
    C Offline
    coderbob
    wrote on last edited by
    #1

    Not sure if I am just not understanding how to use this correctly, but I am not able to edit text with the keyboard if I have a mouseArea defined for it also.

    @
    import Qt 4.7

    Rectangle {
    id: mainWindow

    width: 640; height: 480
    color: "lightgray"

    Rectangle {
    id: box
    anchors.centerIn: parent
    width: ti.width; height: 25;
    color: "white"

     TextInput {
         id: ti;
         text: "This text can not be edited"
    
        MouseArea
        {
           id: mouseArea
           anchors.fill: parent
        }
     }
    

    }
    }
    @

    Just a basic rectangle with a textInput and a mouseArea. I could not find anything in the documentation where I would need to pass a mouse event along so a key event could evaluate.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alexander
      wrote on last edited by
      #2

      Yes, you cannot do it, but it's good question:) How can I track mouse on LineEdit?

      1 Reply Last reply
      0
      • 2 Offline
        2 Offline
        2beers
        wrote on last edited by
        #3

        I think you need to disable the mousearea when you want to enter the text. Not sure what you want to do, but I'm guessing that when a user clicks the TextInput you make some actions based on the onClicked event in MouseArea, then start entering some text. I think you can do this by deleting the mouse area once you clicked on her. :) Not sure if it's the best solution.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mbrasser
          wrote on last edited by
          #4

          Hi,

          You should still be able to edit the text with the keyboard, as long as the TextInput has focus (typically focus is given when you click on it, but you can also assign it manually with e.g. the focus property).

          Regards,
          Michael

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Muby
            wrote on last edited by
            #5

            I have the same problem with this code

            @FocusScope {
            property alias text: masterInput.text
            property string default_text : "Ip Address"

            width: 180;
            height:28
            
            signal acceptedLineInput()
            
            TextInput {
                id: masterInput
                anchors.fill: parent
                selectByMouse:true
                color: "#1678b5"
                selectionColor: "green"
                text: default_text
                font.pixelSize: 12
                focus: true
            
                validator: RegExpValidator {regExp :/([1-9][0-9]{0,2})\.([1-9][0-9]{0,2})\.([1-9][0-9]{0,2})\.([1-9][0-9]{0,2})/}
                MouseArea {
                       hoverEnabled:true
                       anchors.fill: parent
                       onEntered: {
                           Func.checkFocus(masterInput,default_text)
                       }
                       onExited: {
                           Func.checkFocus(masterInput,default_text)
                       }
                   }
                onAccepted: {
                    acceptedLineInput()
                    console.log(acceptableInput)
                }
            
            }
            

            }
            @

            and the Js is :
            @function checkFocus(text_input1,default_text)
            {
            if (text_input1.text == default_text)
            text_input1.text= "";
            else if(text_input1.text === "")
            text_input1.text= default_text;
            }
            @

            I work not to bad but I can't select text on the textInput. Is there a solution or a better way to do what I want ?

            Thanks

            1 Reply Last reply
            0
            • K Offline
              K Offline
              kunal_the_one
              wrote on last edited by
              #6

              I wanted to use TextInput and when user click on it, clear the text. I used code described in my following post.

              http://kunalmaemo.blogspot.com/2011/06/using-textinput-in-qt-quick-qml.html

              1 Reply Last reply
              0
              • E Offline
                E Offline
                ephe
                wrote on last edited by
                #7

                maybe "this post":http://developer.qt.nokia.com/forums/viewthread/13344/ helps

                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