Results 1 to 12 of 12

Thread: How to get the text from textedit when mouse is clicked

  1. #1
    Join Date
    Mar 2006
    Location
    Hyderabad
    Posts
    69
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default How to get the text from textedit when mouse is clicked

    hello everyone,
    I got an application where, when the mouse is Double Clicked in the textedit area, I need to get the entire line in that position. Is there any method of doing it?

    Thanks in advance,
    Sarma.

  2. #2
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: How to get the text from textedit when mouse is clicked

    txtEdit->text()
    a life without programming is like an empty bottle

  3. #3
    Join Date
    Mar 2006
    Location
    Hyderabad
    Posts
    69
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: How to get the text from textedit when mouse is clicked

    Sorry sir,
    That gives the entire text present in the textedit. But I want the line on which the mouse is Double clicked.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to get the text from textedit when mouse is clicked

    Use clicked(int para, int pos) signal and in the slot call text(int para) which returns the text of the given paragraph.

  5. #5
    Join Date
    Mar 2006
    Location
    Hyderabad
    Posts
    69
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: How to get the text from textedit when mouse is clicked

    sir,
    Please tell me in which variable the line is stored so that I can access it and make operations on it.
    I have added the following statement after the declaration of textedit:
    Qt Code:
    1. QObject::connect(te,SIGNAL(clicked(int para,int pos)),this,SLOT(text(int para)));
    To copy to clipboard, switch view to plain text mode 

    Is it correct or it gives any errors. And I would like to tell one thing that I need to get the text if I "Double click the mouse" and in above statement, the signal is simply clicked(). why it is so?
    Last edited by Sarma; 8th March 2006 at 11:45.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to get the text from textedit when mouse is clicked

    Quote Originally Posted by Sarma
    QObject::connect(te,SIGNAL(clicked(int para,int pos)),this,SLOT(text(int para)));
    Parameter names are not allowed in SIGNAL and SLOT macros.

    Try this:
    Qt Code:
    1. QObject::connect( te, SIGNAL( clicked( int, int ) ), this, SLOT( text( int ) ) );
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Mar 2006
    Location
    Hyderabad
    Posts
    69
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: How to get the text from textedit when mouse is clicked

    sir,

    Quote Originally Posted by wysota
    Use clicked(int para, int pos) signal and in the slot call text(int para) which returns the text of the given paragraph.
    Isn't that the signal and the slot should have the same no. of parameters and are of same type.
    I need to get the text if I "Double click the mouse" and in above statement, the signal is simply clicked(). why it is so?

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to get the text from textedit when mouse is clicked

    Quote Originally Posted by Sarma
    Isn't that the signal and the slot should have the same no. of parameters and are of same type.
    No. The slot can have less parameters than the signal (last parameters can be omitted).

    I need to get the text if I "Double click the mouse" and in above statement, the signal is simply clicked(). why it is so?
    Because there is no doubleClicked signal with paragraph coordinates. You'd have to implement that functionality yourself, by finding the paragraph under cursor (QTextEdit has some methods for that) and translating it to the text.

  9. #9
    Join Date
    Mar 2006
    Location
    Hyderabad
    Posts
    69
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: How to get the text from textedit when mouse is clicked

    How would I know the cursor position where the mouse is Double clicked (or) simply clicked in a textedit . I have tried it with getCursorPosition(), but it was of no use.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to get the text from textedit when mouse is clicked

    QCursor::pos()

  11. #11
    Join Date
    Mar 2006
    Location
    Hyderabad
    Posts
    69
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: How to get the text from textedit when mouse is clicked

    Sir,
    That gives the coordinates of the cursor in the screen. But what if I have a large text in the textedit? I need to get this position and based on the scrollbar value, I need to calculate the paragraph in the text where the event occured. And I think this would be cumbersome. Please tell me other solution possible.

    Thanks and regards,
    Sarma.

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to get the text from textedit when mouse is clicked


Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. how to replace mouse clicked to tid
    By wagmare in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 7th October 2008, 10:40
  3. Help text color in TextEdit
    By tho97 in forum Qt Programming
    Replies: 5
    Last Post: 26th March 2008, 08:47
  4. Replies: 7
    Last Post: 20th November 2007, 12:15
  5. visible text of textedit
    By regix in forum Qt Programming
    Replies: 3
    Last Post: 26th June 2006, 09:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.