[SOLVED] Scrolling to a particular line number in the QTextBrowser
-
wrote on 12 Nov 2011, 00:39 last edited by
Hi,
Currently I have this code which goes to a particular line number and makes the text bold. What i want to achieve is that when the QTextBrowser is invoked, it will open to last position of the cursor below and not the start of the QTextBrowser(as default).Please help.
@
QTextDocument *document = my_browser->document();
QTextCursor cursor(document);for(int i=0; i<20 ; i++) { cursor.movePosition(QTextCursor::Down); } cursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor); QTextCharFormat format; format.setFontWeight(QFont::Bold); cursor.mergeCharFormat(format);
@
-
wrote on 15 Nov 2011, 06:01 last edited by
No replies...Someone please suggest me how to go about...
-
wrote on 15 Nov 2011, 15:23 last edited by
You can set position manually:
@cursor.movePosition(QTextCursor::Start);@ -
wrote on 15 Nov 2011, 21:41 last edited by
You could use as alternative the select function of the QTextCursor:
@
cursor.select(QTextCursor::LineUnderCursor);
cursor.mergeCharFormat(format);
@ -
wrote on 16 Nov 2011, 02:54 last edited by
http://stackoverflow.com/questions/3547185/scroll-qtextbrowser-to-the-top
This helped me. Thank you to everyone who tried to help me. I appreciate it.@
QTextDocument *document = my_browser->document();
QTextCursor cursor(document);for(int i=0; i<line_number-1 ; i++) { cursor.movePosition(QTextCursor::Down); } cursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor); my_browser->setTextCursor(cursor); mainLayout->addWidget(my_browser); setLayout(mainLayout);
@
1/5