Results 1 to 13 of 13

Thread: Check Selected Content

  1. #1
    Join Date
    May 2009
    Posts
    94
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Post Check Selected Content

    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?
    Last edited by bismitapadhy; 15th July 2009 at 12:55.

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Check Selected Content

    Check for any line endings are in selected text or not.

  3. #3
    Join Date
    May 2009
    Posts
    94
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Check Selected Content

    Quote Originally Posted by yogeshgokul View Post
    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.

  4. #4
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Thanks
    7
    Thanked 25 Times in 24 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Check Selected Content

    how to check line end char?

    the following code also not working.
    Qt Code:
    1. QTextCursor cursor = m_pEditor->textCursor ();
    2. if(cursor.hasSelection ())
    3. selection = cursor.selectedText ();
    4. if(selection.contains('\n'))
    5. QMessageBox::information(this,tr("Editor"),tr("selected string is multiline"));
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Check Selected Content

    Check '\n', '\r', or their combinations.

  6. #6
    Join Date
    May 2009
    Posts
    94
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Check Selected Content

    Quote Originally Posted by yogeshgokul View Post
    Check '\n', '\r', or their combinations.
    It is not working.

  7. #7
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Check Selected Content

    Quote Originally Posted by bismitapadhy View Post
    I selected more than one line.
    In which widget you are selecting text?
    QTextEdit ??

  8. #8
    Join Date
    May 2009
    Posts
    94
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Check Selected Content

    Quote Originally Posted by yogeshgokul View Post
    In which widget you are selecting text?
    QTextEdit ??
    Yes QTextEdit.

  9. #9
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Check Selected Content

    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

  10. #10
    Join Date
    May 2009
    Posts
    94
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Check Selected Content

    Quote Originally Posted by yogeshgokul View Post
    How you are getting the selected text ?
    QTextCursor.selectedText();

  11. #11
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Check Selected Content

    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

  12. #12
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Thanks
    7
    Thanked 25 Times in 24 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Check Selected Content

    check this is working:
    Qt Code:
    1. if(selection.contains(QChar::ParagraphSeparator) || selection.contains(QChar::LineSeparator))
    2. QMessageBox::information(this,tr("Editor"),tr("selected string is multiline"));
    To copy to clipboard, switch view to plain text mode 

  13. The following user says thank you to rajesh for this useful post:

    bismitapadhy (15th July 2009)

  14. #13
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Check Selected Content

    Yepp, thats cool,

Similar Threads

  1. Why is my application's CPU usage always > 50%
    By richardander in forum Qt Programming
    Replies: 10
    Last Post: 14th October 2010, 22:22
  2. QTcpSocket exception.
    By Fastman in forum Qt Programming
    Replies: 9
    Last Post: 29th January 2008, 13:51
  3. Qwizard crashed when created in a slot
    By joshlareau in forum Qt Programming
    Replies: 9
    Last Post: 15th January 2008, 09:16
  4. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  5. QTableView paints too much
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2006, 18:42

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
  •  
Qt is a trademark of The Qt Company.