Results 1 to 3 of 3

Thread: How to get text of last line only in QTextEdit?

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

    Question How to get text of last line only in QTextEdit?

    How to get text of last line from QTextEdit, and how to set cursor at the end of line or text? Actually I want to blink the cursor at the end of text when textedit get focus through code.

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to get text of last line only in QTextEdit?

    You can go to any part of the document and play with it using

    QTextDocument
    QTextBlock
    QTextCursor

    and probably some other related classes.

  3. #3
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to get text of last line only in QTextEdit?

    Quote Originally Posted by rajesh
    How to get text of last line from QTextEdit, and how to set cursor at the end of line or text? Actually I want to blink the cursor at the end of text when textedit get focus through code.
    have a look on file:
    http://ciz.ch/svnciz/_STATIC_LIBS_QT...it/html_edit.h
    http://ciz.ch/svnciz/_STATIC_LIBS_QT.../html_edit.cpp

    this sample make a href link or unlink a text

    Qt Code:
    1. void HTML_Edit::makehrefLink()
    2. {
    3. bool is_selected = html_area->textCursor().hasSelection();
    4. QString sthtml = html_area->textCursor().selectedText();
    5. if (vol_18->isChecked()) {
    6. QString ltext;
    7. if (sthtml.size() < 1) {
    8. sthtml= "Text to link";
    9. }
    10. Href_Gui::self( this )->text_href->setText(sthtml);
    11. Href_Gui::self( this )->exec();
    12. if (Href_Gui::self) {
    13. QStringList data = Href_Gui::_self->GetUserConfig();
    14. if (data.count() > 0) {
    15. /*qDebug() << "### linerr rrr " << QString(data.at(0));
    16.   qDebug() << "### linerr rrr " << QString(data.at(1));
    17.   qDebug() << "### linerr rrr " << QString(data.at(2));*/
    18. ltext ="<a href=\""+QString(data.at(1))+"#target="+QString(data.at(2))+"\">"+QString(data.at(0))+"</a>";
    19. QTextDocumentFragment fragment = QTextDocumentFragment::fromHtml(ltext);
    20. html_area->textCursor().insertFragment(fragment);
    21. vol_18->setChecked(false);
    22. }
    23. }
    24. } else {
    25. QTextDocumentFragment fragment = QTextDocumentFragment::fromHtml(sthtml);
    26. html_area->textCursor().insertFragment(fragment);
    27. }
    28.  
    29. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QTextEdit API questions (plain text)
    By Gaspar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 07:03
  2. coordinates of selected text in QTextEdit
    By sreedhar in forum Qt Programming
    Replies: 1
    Last Post: 15th May 2006, 18:22
  3. a Text Editor with line numbers...
    By fullmetalcoder in forum Qt Programming
    Replies: 47
    Last Post: 5th April 2006, 12:10
  4. Problem with inserting text into QTextEdit
    By xorrr in forum Qt Programming
    Replies: 0
    Last Post: 6th February 2006, 12:45
  5. QTextEdit Justify align making work
    By dec0ding in forum Qt Programming
    Replies: 2
    Last Post: 13th January 2006, 13: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.