Results 1 to 3 of 3

Thread: Disable QTextCursor Mouse click repositioning

  1. #1
    Join Date
    Jan 2007
    Posts
    209
    Thanks
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Disable QTextCursor Mouse click repositioning

    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::MouseButtonPr ess, 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?

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Disable QTextCursor Mouse click repositioning

    Quote Originally Posted by VireX View Post
    I tried doing this to keep the cursor at the end of all the TEXT. However, this did not work:
    Qt Code:
    1. qtxtbrowser->textCursor().clearSelection();
    2. qtxtbrowser->textCursor().movePosition(QTextCursor::End);
    3. qtxtbrowser->insertHtml(qsData+"<br>");
    To copy to clipboard, switch view to plain text mode 
    That is modifying a copy. It should be done in this way:
    Qt Code:
    1. QTextCursor cursor = qtxtbrowser->textCursor();
    2. cursor.clearSelection();
    3. cursor.movePosition(QTextCursor::End);
    4. qtextbrowser->setTextCursor(cursor); // <--
    5. qtxtbrowser->insertHtml(qsData+"<br>");
    To copy to clipboard, switch view to plain text mode 
    By the way, Qt 4.2 introduces a new convenience method for moving the cursor. You could try something like this:
    Qt Code:
    1. qtxtbrowser->moveCursor(QTextCursor::End);
    2. qtxtbrowser->insertHtml(qsData+"<br>");
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    VireX (3rd April 2007)

  4. #3
    Join Date
    Jan 2007
    Posts
    209
    Thanks
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Disable QTextCursor Mouse click repositioning

    You're amazing thank you so much . Especially on the fast reply <3.

Similar Threads

  1. Replies: 1
    Last Post: 9th February 2007, 09:41
  2. QGraphicsScene Click / Double Click
    By philentropist in forum Qt Programming
    Replies: 1
    Last Post: 9th February 2007, 04:32
  3. Replies: 4
    Last Post: 31st August 2006, 12:11

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.