Results 1 to 4 of 4

Thread: QTextEdit

  1. #1
    Join Date
    Mar 2010
    Posts
    7
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default QTextEdit

    Hello everyone,

    I'm trying to make the porting from qt3 to qt4 of one program. Q3TextEdit is used in the first one and it returns the cursor position as (paragraph, index) and now I've found the problem that in qt4 I don't know how to get them.
    Can anybody help me? Can anybody tell me how to get the paragraph and the index in the paragraph??

    Thank you very much in advance! (and sorry for my bad english )

  2. #2
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextEdit

    Hi!

    Qt Code:
    1. QTextEdit* te = new QTextEdit()
    2. ..
    3. QTextCursor cursor = te->textCursor();
    4. int paragraph = cursor.blockNumber();
    5.  
    6. // Raw position in document
    7. //cursor.position();
    8.  
    9. // Position from linestart = your index?
    10. int index = cursor.columnNumber();
    To copy to clipboard, switch view to plain text mode 
    HIH

    See: QTextCursor!

    Johannes

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

    titoaii (13th April 2010)

  4. #3
    Join Date
    Mar 2010
    Posts
    7
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QTextEdit

    Thank you Johannes,

    Now I've found another problem, when I want to set the cursor in a line "line" and in a column "index", I've just tried, to do the following:
    Qt Code:
    1. QTextEdit * editor;
    2. //Moves the cursor to the beginning of the document
    3. editor->textCursor().setPosition(0,QTextCursor::MoveAnchor);
    4. //Now moves the cursor to the line "line" and in the column "index"
    5. editor->textCursor().movePosition(QTextCursor::Down, QTextCursor::MoveAnchor,line-1);
    6. editor->textCursor().movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor, index);
    To copy to clipboard, switch view to plain text mode 

    However, everything I get is the cursor at the same position as the one before the execution of this code.
    I suppose I'm doing it in a bad way. But if you or any can help me, it could be awesome

    Thank you!

  5. #4
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextEdit

    Try:

    Qt Code:
    1. QTextEdit * editor;
    2. //Moves the cursor to the beginning of the document
    3. QTextCursor tc = editor->textCursor();
    4. tc.setPosition(0,QTextCursor::MoveAnchor);
    5. //Now moves the cursor to the line "line" and in the column "index"
    6. tc.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor,line-1);
    7. tc.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor, index);
    8. editor->setTextCursor(tc);
    To copy to clipboard, switch view to plain text mode 

    Johannes

  6. The following user says thank you to JohannesMunk for this useful post:

    titoaii (15th April 2010)

Similar Threads

  1. QTextEdit
    By qoo in forum Newbie
    Replies: 6
    Last Post: 28th July 2009, 19:05
  2. QTextEdit
    By RY in forum Newbie
    Replies: 5
    Last Post: 15th October 2008, 18:52
  3. QTextEdit
    By ocean in forum Qt Programming
    Replies: 4
    Last Post: 13th September 2008, 13:19
  4. QTextEdit
    By veda in forum Qt Programming
    Replies: 4
    Last Post: 11th September 2007, 08:30
  5. Replies: 1
    Last Post: 16th February 2007, 08:22

Tags for this Thread

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.