Results 1 to 6 of 6

Thread: [Qt4] QTextEdit & cursor visibility

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2006
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: [Qt4] QTextEdit & cursor visibility

    Well, it does not work. The line is still highlighted but only the begining of the file is visible

  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: [Qt4] QTextEdit & cursor visibility

    Ok, I see the problem. QWidget's geometry is calculated upon first show event. You should move the ensureCursorVisible() call in QTextEdit's showEvent() or into a slot connected to a single shot timer with timeout 0. This ensures that the geometry is constructed properly before trying to do operations which rely on widget's geometry.

    Either subclass QTextEdit and override it's showEvent():
    Qt Code:
    1. void MyTextEdit::showEvent(QShowEvent* event)
    2. {
    3. QTextEdit::showEvent(event);
    4.  
    5. static bool initialized = false;
    6. if (!initialized)
    7. {
    8. ensureCursorVisible();
    9. initialized = true;
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    Or use the timer technique:
    Qt Code:
    1. // add this in place where you had "editor->ensureCursorVisible();"
    2. QTimer::singleShot(0, this, SLOT(initialize()));
    3.  
    4. // declared as a slot
    5. void BodyWidget::initialize()
    6. {
    7. // QTextEdit* editor moved as a member variable
    8. editor->ensureCursorVisible();
    9. }
    10. editor->ensureCursorVisible();
    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:

    Ti_Thom (10th October 2006)

  4. #3
    Join Date
    Oct 2006
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: [Qt4] QTextEdit & cursor visibility

    I was also thinking about the widget's geometry computation and tryed to put "editor->ensureCursorVisible();" at the end of the BodyWidget build function, the visible text was not the right part.

    I just tryed your 2nd technique, it seems to work as expected. Thanks !

  5. #4

    Default Re: [Qt4] QTextEdit & cursor visibility

    QTextCursor* highlightCursor;
    QTextEdit *ui_textEdit;
    ...
    ui_textEdit->setTextCursor(*highlightCursor);
    ui_textEdit->ensureCursorVisible();

    just make sure u set the cursor using setTextCursor instead of ui_textEdit->textCursor().setPosition() and u call ensureCursorVisible after that.

    Himanshu Dahiya

Similar Threads

  1. QTextEdit API questions (plain text)
    By Gaspar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 06:03
  2. [Qt4] Can QTextEdit be overflowed?
    By naresh in forum Qt Programming
    Replies: 5
    Last Post: 14th March 2006, 13:28
  3. [QT 4] QTextEdit performance
    By fellobo in forum Qt Programming
    Replies: 8
    Last Post: 6th March 2006, 19:27
  4. Painting to QTextEdit
    By gesslar in forum Qt Programming
    Replies: 8
    Last Post: 18th February 2006, 18:40
  5. Obtaining clean (x)html from QTextEdit
    By ccf_h in forum Qt Programming
    Replies: 1
    Last Post: 5th February 2006, 14:47

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.