Results 1 to 6 of 6

Thread: QGraphicsTextItem ensure cursor visible

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2010
    Location
    Veszprém, Hungary
    Posts
    34
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsTextItem ensure cursor visible

    At last I found the way:

    Qt Code:
    1. QGraphicsTextItem::keyPressEvent(event);
    2. QTextBlock block = document()->findBlock(textCursor().position());
    3. QTextLine line = block.layout()->lineForTextPosition(textCursor().positionInBlock());
    4. qreal cursor_y_position = document()->documentLayout()->blockBoundingRect(block).y() + line.y();
    5. qreal line_height = line.height();
    6. qDebug("New cursor position: %.2f %.2f", cursor_y_position, line_height);
    7. if ( _actual_position > cursor_y_position )
    8. {
    9. ScrollToPosition(cursor_y_position);
    10. }
    11. if ((_actual_position + _height) < (cursor_y_position + line_height))
    12. {
    13. ScrollToPosition(cursor_y_position + line_height - _height);
    14. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Nov 2009
    Location
    Sacramento, CA
    Posts
    24
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsTextItem ensure cursor visible

    Nice Code snippet, but what are actual_position and _height?

    Does actual_position = textCursor().position() and _height = document().size().height()?

Similar Threads

  1. How to ensure widget is visible
    By arturo182 in forum Qt Programming
    Replies: 3
    Last Post: 1st September 2009, 00:45
  2. How can to change the QGraphicsTextItem 's cursor width?
    By robertkun in forum Qt Programming
    Replies: 1
    Last Post: 11th August 2009, 03:49
  3. cursor in qgraphicstextitem
    By Noxxik in forum Qt Programming
    Replies: 0
    Last Post: 15th March 2009, 12:04
  4. Hiding the cursor in QGraphicsTextItem
    By yartiss in forum Qt Programming
    Replies: 3
    Last Post: 13th March 2008, 13:19
  5. Cursor not visible
    By jpujolf in forum Qt Programming
    Replies: 8
    Last Post: 11th May 2007, 14:05

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.