×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Regular Contributor
    Join Date
    Nov 2011
    Posts
    104

    How to get the text from the button into Textfield in qt qml?

    Hi all,
    I am trying to display the text inside a button in a Textfield using Qt Qml.

    I am having a button with a text "Apple" and a Textfield which is blank.

    I need to display the text which is inside the button in the Textfield which is blank when clicked on the button.


    Anyone come with the answer to solve my problem.

    Here is my code:

    Button {
    id: button13
    x: 76
    y: 447
    text: "Apple"
    onClicked: {

    t.visible = text
    }


    TextField {
    id: t
    x:76
    y:129
    width: 230
    height: 50
    text: ""

    }


    Thanks in advance,
    Harish

  2. #2
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Noida,India
    Posts
    4,006

    Re: How to get the text from the button into Textfield in qt qml?

    Quote Originally Posted by mkhpad View Post

    Code:
    Button {
    id: button13
    x: 76
    y: 447
    text: "Apple"
    onClicked: {
    
    t.text = text
    }
    
    
    TextField {
    id: t
    x:76
    y:129
    width: 230
    height: 50
    text: ""
    
    }
    Try with above changed code(see the change in bold)

  3. #3
    Regular Contributor
    Join Date
    Nov 2011
    Posts
    104

    Re: How to get the text from the button into Textfield in qt qml?

    Thank You Vineet for your answer.
    I tried on my own and was doing something as:


    Button {
    id: button13
    x: 76
    y: 447
    text: "Apple"
    onClicked: {

    t.text= Apple
    }


    TextField {
    id: t
    x:76
    y:129
    width: 230
    height: 50
    text: ""

    }

    It was displaying the text in a hard-coded manner but from your answer i got the right solution...

    Cheers vineet....Now i am having two buttons with different text inside it.

    For example:in 1st button "Apple" and in 2nd button "Banana" i need to display the text inside the two buttons in the text field.....

    Which means i need to display AppleBanana in the textfield...


    I mean:How to append those two values into the text field.


    Thanks in advance vineet again,
    Harish

  4. #4
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Noida,India
    Posts
    4,006

    Re: How to get the text from the button into Textfield in qt qml?

    Well you can declare a string variable at the top & append the text values from two button into that variable & set it as text for textfield when a click of button is there on any of the buttons:

    Code:
     property string butntext: ""
    Button {
    text: "Apple"
    onClicked:
            {
                butntext = text + btn2.text;
                t.text=butntext 
            }
    }
    
    Button {
    id:btn2
    text: "banana"
    }

  5. #5
    Regular Contributor
    Join Date
    Nov 2011
    Posts
    104

    Re: How to get the text from the button into Textfield in qt qml?

    I hope you are helping me a lot to come with the answer.

    From your code it shows that when clicked on button1 it displays both the text in a single click.(i.e. it displays AppleBanana in a single click)

    But what i am expecting is when clicked on button1 it should display Apple in textfield and when clicked on button2 it should display as Banana. which means AppleBanana finally and when done in reverse i.e. when button2 is clicked first it should display Banana and when clicked on button1 next it should display Apple and the final result in textfield must be BananaApple..

    Hope you understood what i am looking for is?I feel sorry for my query which was not clear in my last post.

  6. #6
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Noida,India
    Posts
    4,006

    Re: How to get the text from the button into Textfield in qt qml?

    Ok, you can get the text of button A on the click event of Button B. Then the string in which you get the button A's text, append with it the text of button B & finally set that text as content for textfield.

    Code:
    Button
    {
    id: BtnA
    }
    Button
    {
    id:BtnB
    on click: 
    {
    
    t.txt = get BtnA's text + BtnB text
    }
    }

  7. #7
    Regular Contributor
    Join Date
    Nov 2011
    Posts
    104

    Re: How to get the text from the button into Textfield in qt qml?

    Vineet i think that you misunderstood my question.

    What i am expecting is:From the first i explain you;

    I have two buttons.
    *button1 with the text "Apple"
    *button2 with the text "Banana"

    and a Textfield which is blank.


    When clicked on button1 it should display the text "Apple" in the Textfield.
    When clicked on button2 it should display the text including "AppleBanana" in the Textfield.

    and in reverse:
    Now i close my application and run it again.This time i like to click button2 first and the Textfield should display only "Banana" and then when clicked on button1 the text should be as "BananaApple"...


    On the whole what i am trying is when clicked on each of the item it should display its text in textfield without deleting the previous one.

    Thank you Vineet anyway.I think my question is more clear this time...

  8. #8
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Noida,India
    Posts
    4,006

    Re: How to get the text from the button into Textfield in qt qml?

    See the code i have pasted in #6 carefully, i suggested the same which you are asking.

    1) On Click of Button A , set the text of textfield with that of button A

    2) On the click of Button B get the text of button A OR get the text of textfield , append that text with that of Button B's text & finally set the resultant text as text for textfield.
    Last edited by vineet.jain; 2012-01-24 at 10:45.

  9. #9
    Regular Contributor
    Join Date
    Nov 2011
    Posts
    104

    Re: How to get the text from the button into Textfield in qt qml?

    I got it vineet thanks a lot.

    I got want i needed from you.

    Cheers again....

Similar Threads

  1. LWUIT TextField - Removing InputModeOrder Text "Abc" from TextField
    By vishal.vpb in forum Mobile Java General
    Replies: 1
    Last Post: 2011-11-14, 06:29
  2. green call button action for textField in S40
    By Ahmed_Mohsen in forum Mobile Java General
    Replies: 2
    Last Post: 2010-09-20, 21:56
  3. Replies: 8
    Last Post: 2010-05-20, 18:22
  4. On button click, send value to textfield
    By LWCARAB in forum Symbian
    Replies: 2
    Last Post: 2010-03-18, 13:20
  5. How to delete text in textfield?
    By lkwan2001 in forum Mobile Java General
    Replies: 1
    Last Post: 2006-02-14, 01:50

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×