TextInput & MouseArea



  • 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.



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



  • 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.



  • 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



  • 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



  • 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




Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.