PDA

View Full Version : Disable QTextCursor Mouse click repositioning



VireX
3rd April 2007, 07:35
See I have a text browser that works great, I use
insertHtml("<br>%1") for texts, and it works great.. I add this line over and over, and it makes a new line each time. Until the user clicks on the QTextBrowser (like somewhere on it), and thats when it messes up and starts inserting it in the middle of the page, or wherever the QTextBrowser is clicked.

I tried doing this to keep the cursor at the end of all the TEXT. However, this did not work:
qtxtbrowser->textCursor().clearSelection();
qtxtbrowser->textCursor().movePosition(QTextCursor::End);
qtxtbrowser->insertHtml(qsData+"<br>");

I also thought about doing something like this: qtxtbrowser->mousePressEvent(QMouseEvent(QEvent::MouseButtonPre ss, QPoint(1,1), Qt::LeftButton, ));
but I have no clue how to do this, and there are no examples anywhere I looked.

Is there a way to disable this left click feature or just keep the cursor at the bottom of all the inserted text?

jpn
3rd April 2007, 07:40
I tried doing this to keep the cursor at the end of all the TEXT. However, this did not work:


qtxtbrowser->textCursor().clearSelection();
qtxtbrowser->textCursor().movePosition(QTextCursor::End);
qtxtbrowser->insertHtml(qsData+"<br>");


That is modifying a copy. It should be done in this way:


QTextCursor cursor = qtxtbrowser->textCursor();
cursor.clearSelection();
cursor.movePosition(QTextCursor::End);
qtextbrowser->setTextCursor(cursor); // <--
qtxtbrowser->insertHtml(qsData+"<br>");

By the way, Qt 4.2 introduces a new convenience method for moving the cursor. You could try something like this:


qtxtbrowser->moveCursor(QTextCursor::End);
qtxtbrowser->insertHtml(qsData+"<br>");

VireX
3rd April 2007, 08:08
You're amazing thank you so much :). Especially on the fast reply <3.