PDA

View Full Version : How to get the text from textedit when mouse is clicked



Sarma
8th March 2006, 11:06
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.

zlatko
8th March 2006, 11:28
txtEdit->text()

Sarma
8th March 2006, 11:34
Sorry sir,
That gives the entire text present in the textedit. But I want the line on which the mouse is Double clicked.

wysota
8th March 2006, 11:43
Use clicked(int para, int pos) signal and in the slot call text(int para) which returns the text of the given paragraph.

Sarma
8th March 2006, 12:09
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:


QObject::connect(te,SIGNAL(clicked(int para,int pos)),this,SLOT(text(int para)));


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?

jacek
8th March 2006, 15:54
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:
QObject::connect( te, SIGNAL( clicked( int, int ) ), this, SLOT( text( int ) ) );

Sarma
9th March 2006, 10:06
sir,



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?

wysota
9th March 2006, 10:10
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.

Sarma
9th March 2006, 10:20
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.

wysota
9th March 2006, 10:23
QCursor::pos()

Sarma
9th March 2006, 10:50
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.

wysota
9th March 2006, 10:57
QWidget::mapFromGlobal() (http://doc.trolltech.com/4.1/qwidget.html#mapFromGlobal)