[Qt-qml] [QML] fail to selectAll in TextInput

Miao, Qiankun qiankun.miao at intel.com
Fri Jun 17 12:45:26 CEST 2011


The timer works well now. Thanks very much.

> -----Original Message-----
> From: Timo Strömmer [mailto:timo.strommer at symbio.com]
> Sent: Friday, June 17, 2011 12:01 AM
> To: Miao, Qiankun; qt-qml at trolltech.com; qt-qml at qt.nokia.com
> Subject: RE: [QML] fail to selectAll in TextInput
> 
> Hi,
> 
> I think when you click on the TextInput, the click event coming after
> focus event clears the just-made selection. It works if you switch
> between windows while the TextInput has focus. I'm not sure what would
> be optimal solution, but you could try delaying selectAll with a timer
> or filtering the next mouse event or some other tricks.
> 
>     - Timo
> ________________________________________
> From: qt-qml-bounces+timo.strommer=symbio.com at qt.nokia.com [qt-qml-
> bounces+timo.strommer=symbio.com at qt.nokia.com] on behalf of Miao,
> Qiankun [qiankun.miao at intel.com]
> Sent: Thursday, June 16, 2011 4:55 PM
> To: qt-qml at trolltech.com; qt-qml at qt.nokia.com
> Subject: [Qt-qml] [QML] fail to selectAll in TextInput
> 
> Hi, there
> 
> I met some issue when I use TextInput. I tried to selectAll() when
> activefocus is true and unselectAll when activefocus is false. But it
> doesn't work. See following code. Is there a method to implement my
> requirement?
> 
> import Qt 4.7
> Rectangle {
>     id: rectangle
>     width: 600
>     height: 400
>     MouseArea {
>       anchors.fill: parent
>       onClicked: {
>         rectangle.forceActiveFocus();
>       }
>     }
>     TextInput {
>         anchors.centerIn: parent
>         id: textinput
>         text: "Hello,\n World!"
>         cursorVisible: true
>         selectByMouse: true
>         selectedTextColor: "yellow"
>         selectionColor: "royalblue"
>         width: parent.width/2
>         height: parent.height/2
>         onActiveFocusChanged: {
>           if (activeFocus == true) {
>             selectAll();
>           }
>           else {
>             select(0,0);
>           }
>         }
>     }
> }


More information about the Qt-qml mailing list