Results 1 to 4 of 4

Thread: QTextEdit : adding Text at the Same Location

  1. #1
    Join Date
    Jun 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QTextEdit : adding Text at the Same Location

    I am writing an application for Extraction of file.
    The text Editor is supposed to show File Name and amount of data extracted .
    This is How it should look :

    File Name :x
    Time Start :

    Completed <var> % of ConstantSize

    The variable var is continually varied .

    QTextCursor cursor(TEXT->textCursor())
    pos=cursor.position();
    TEXT->setTEXTCursor(cursor);
    TEXT->setText(var);

    However Each Time The Text is written it is clearing up the screen.
    I have tried insertPlaintext. That is appending.

    Inputs appreciated..

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,709
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QTextEdit : adding Text at the Same Location

    You are not doin anything with the cursor.
    You create a copy of the cursor from the document, you read the position (but don't do with it anything), and then set the cursor back as it was.

    What you want is:
    1. get the correct position of the text you want to replace
    2. select it .
    3. use QTextCursor::insertText() to overwrite the old (now selected) value

    That is one way.
    There are others way as well.

    See QTextCursor for more details, they have example code in there too.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jun 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTextEdit : adding Text at the Same Location

    Sorri I missed one line to which you were referring,

    QTextCursor cursor(TEXT->textCursor())
    pos=cursor.position();
    cursor.setPosition(pos,cursor.MoveAnchor);
    TEXT->setTEXTCursor(cursor);
    TEXT->setText(var);

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,709
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QTextEdit : adding Text at the Same Location

    Ok, but if you read my post you see that its not the only problem.
    Try what I suggested.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. How to interactively adding text to scene
    By lni in forum Qt Programming
    Replies: 4
    Last Post: 13th February 2010, 17:04
  2. QTextEdit::text()
    By hazardpeter in forum Newbie
    Replies: 2
    Last Post: 5th August 2009, 21:13
  3. QTextEdit + paste rich text as plain text only
    By Yong in forum Qt Programming
    Replies: 2
    Last Post: 6th February 2008, 16:45
  4. QTextEdit -> add Text
    By ape in forum Newbie
    Replies: 16
    Last Post: 19th December 2007, 14:59
  5. QTextEdit and mark Text
    By J-jayz-Z in forum Qt Programming
    Replies: 12
    Last Post: 28th September 2007, 00:14

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.