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

Miao, Qiankun qiankun.miao at intel.com
Fri Jun 17 06:38:53 CEST 2011


When I click textinput it should get activefocus.
I use rectangle.forceActiveFocus() to foucs out textinput for unselectAll.

> -----Original Message-----
> From: Paul Plaquette [mailto:paul.plaquette at linux.intel.com]
> Sent: Friday, June 17, 2011 7:38 AM
> To: Miao, Qiankun
> Cc: qt-qml at trolltech.com; qt-qml at qt.nokia.com
> Subject: Re: [Qt-qml] [QML] fail to selectAll in TextInput
> 
> On 06/16/2011 03:55 PM, Miao, Qiankun wrote:
> > 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?
> 
> hi,
> 
> On 06/16/2011 03:55 PM, Miao, Qiankun wrote:
>  >        onClicked: {
>  >
>  >          rectangle.forceActiveFocus();
>  >
>  >        }
>  >
> hello,
> 
> did you tried with   textinput.forceActiveFocus();
> 
> rectangle.forceActiveFocus(); is actually changing the property
> "activeFocus" for the rectangle not for the text input
> 
>   you put the handler  for onActiceFocusChanged in your TextInput
> object.
> 
> hope this helps !
> 
> Paul
> 
> >
> > 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);
> >
> > }
> >
> > }
> >
> > }
> >
> > }
> >
> >
> >
> > _______________________________________________
> > Qt-qml mailing list
> > Qt-qml at qt.nokia.com
> > http://lists.qt.nokia.com/mailman/listinfo/qt-qml



More information about the Qt-qml mailing list