Results 1 to 10 of 10

Thread: qtextcursor setposition doesn't work

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2012
    Posts
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: qtextcursor setposition doesn't work

    But the cursor is set to -1 when no match is found by the find method in the findslot:
    Qt Code:
    1. void FindWidget::slotFind()
    2. {
    3. QTextCursor cursor = mTextpage->textCursor();
    4.  
    5. if (cursor.anchor() == -1) {
    6. cursor = mTextpage->document()->find(findEdit->text(), cursor, QTextDocument::FindCaseSensitively);
    7. } else {
    8. cursor = mTextpage->document()->find(findEdit->text(), cursor.anchor(), QTextDocument::FindCaseSensitively);
    9. }
    10. mTextpage->setTextCursor(cursor);
    11. this->setBackground();
    12. }
    To copy to clipboard, switch view to plain text mode 
    So my thought was, to set the position of the cursor in the slotClose to 0, if it is -1. But this doesn't work and I definetly don't understand why.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: qtextcursor setposition doesn't work

    Quote Originally Posted by doc_symbiosis View Post
    But the cursor is set to -1 when no match is found by the find method in the findslot:
    So don't put it there! Just don't call setTextCursor() if you don't want to.

    So my thought was, to set the position of the cursor in the slotClose to 0, if it is -1. But this doesn't work and I definetly don't understand why.
    It doesn't work because the cursor is invalid. It's probably even not tied to your document. Use the code I gave you in my previous post instead.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Example in Qt labs doesn't work
    By matko in forum Newbie
    Replies: 1
    Last Post: 19th November 2009, 19:59
  2. macdeployqt doesn't work at all.
    By pherthyl in forum Installation and Deployment
    Replies: 1
    Last Post: 10th July 2009, 01:42
  3. Shortcut doesn't work
    By stella1016 in forum Qt Programming
    Replies: 1
    Last Post: 28th May 2009, 03:37
  4. QRegExp doesn't seem to work as it should
    By thomaspu in forum Qt Programming
    Replies: 3
    Last Post: 21st December 2007, 08:49
  5. setTabStopWidth doesn't work
    By discostu in forum Qt Programming
    Replies: 3
    Last Post: 19th November 2007, 09:29

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
  •  
Qt is a trademark of The Qt Company.