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