PDA

View Full Version : Check Selected Content



bismitapadhy
15th July 2009, 12:21
I selected more than one line.
I am geting the selected content using cursor.selectedText();
I want to check only one line content is selected or more than one line content selected?
How can i check this?

yogeshgokul
15th July 2009, 13:12
Check for any line endings are in selected text or not.

bismitapadhy
15th July 2009, 13:22
Check for any line endings are in selected text or not.How to check for line ending in the selected text.
If i am checking for "\n" it is not working.

rajesh
15th July 2009, 13:24
how to check line end char?

the following code also not working.

QTextCursor cursor = m_pEditor->textCursor ();
if(cursor.hasSelection ())
selection = cursor.selectedText ();
if(selection.contains('\n'))
QMessageBox::information(this,tr("Editor"),tr("selected string is multiline"));

yogeshgokul
15th July 2009, 13:27
Check '\n', '\r', or their combinations.

bismitapadhy
15th July 2009, 13:31
Check '\n', '\r', or their combinations.It is not working.

yogeshgokul
15th July 2009, 13:32
I selected more than one line.

In which widget you are selecting text?
QTextEdit ??

bismitapadhy
15th July 2009, 13:34
In which widget you are selecting text?
QTextEdit ??Yes QTextEdit.

yogeshgokul
15th July 2009, 13:37
Can you tell me, how you are getting the selected text ?
I guess you have to change line wrap and word wrap properties to QTextEdit::NoWrap

bismitapadhy
15th July 2009, 13:40
How you are getting the selected text ?QTextCursor.selectedText();

yogeshgokul
15th July 2009, 13:42
I got your problem.

If the selection obtained from an editor spans a line break, the text will contain a Unicode U+2029 paragraph separator character instead of a newline \n character. Use QString::replace() to replace these characters with newlines. enjoy :)

rajesh
15th July 2009, 13:45
check this is working:

if(selection.contains(QChar::ParagraphSeparator) || selection.contains(QChar::LineSeparator))
QMessageBox::information(this,tr("Editor"),tr("selected string is multiline"));

yogeshgokul
15th July 2009, 13:48
Yepp, thats cool,:cool: