Results 1 to 10 of 10

Thread: Make the cursor visible in textEdit (Qt3.3.5)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Make the cursor visible in textEdit (Qt3.3.5)

    Check the attachment. It's a quick & dirty solution and needs some additional work, but it should at least get you started.
    Attached Files Attached Files

  2. #2
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Make the cursor visible in textEdit (Qt3.3.5)

    Quote Originally Posted by jacek View Post
    Check the attachment. It's a quick & dirty solution and needs some additional work, but it should at least get you started.
    Hi jacek thank you for your reply,
    I went through your solution. I found it helpful.

    But I have still one more problem. The solution what you have
    provided is for vertical scrollBar but I need the same for horizontal one.

    I have done some modification to your code but is unable to calculate the exact points( x and y coordinates)

    Is there anything in QTextEdit which can give me the current QPoint
    position of the cursor.

    Here is the code

    Qt Code:
    1. Test()
    2. {
    3. QSignalMapper *m = new QSignalMapper( this );
    4. for( int i = 0; i < N; ++i )
    5. {
    6. _t[i] = new QTextEdit( viewport() );
    7. _t[i]->resize( WIDTH, HEIGHT );
    8. _t[i]->setVScrollBarMode( QScrollView::AlwaysOff );
    9. _t[i]->setHScrollBarMode( QScrollView::AlwaysOff );
    10. _t[i]->setWrapPolicy ( QTextEdit::AtWordOrDocumentBoundary );
    11. addChild( _t[i] );
    12. m->setMapping( _t[i], i );
    13. connect( _t[i], SIGNAL( textChanged() ), m, SLOT( map() ) );
    14. }
    15.  
    16. connect( m, SIGNAL( mapped(int) ), this, SLOT( resize(int) ) );
    17. updatePositions();
    18. }
    19.  
    20. private slots:
    21. void resize( int i )
    22. {
    23. QTextEdit *t = _t[i];
    24. int w = t->width();
    25.  
    26. QFontMetrics fm(t->QWidget::font());
    27. int fontWidth = fm.width(t->text());
    28. int contentX = QscrollView::visibleWidth();
    29.  
    30. if( fontWidth >= contentX )
    31. {
    32. int para = 0;
    33. int index = 0;
    34.  
    35. t->getCursorPosition( &para, &index );
    36.  
    37. QRect r( t->paragraphRect( para ) );
    38. int line = t->lineOfChar( para, index );
    39. int totLines = t->linesOfParagraph( para );
    40.  
    41. //the problem is here. Here y gives me the correct value but how do I get the correct
    42. //x value. If I have the current QPoint position of the cursor I need not calculate the
    43. //x and y values and my work becomes easier
    44. int x = fontWidth; //fontWidth return the total pixelWidth of the text in current textEdit
    45. int y = r.top() + ( line * r.height() ) / totLines;
    46.  
    47. QPoint pt( x, y );
    48. pt = t->mapToParent( pt );
    49. pt = viewportToContents( pt );
    50. QScrollView::ensureVisible( pt.x(), pt.y() );
    51. }
    52. }
    To copy to clipboard, switch view to plain text mode 

    thanks in advance

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Make the cursor visible in textEdit (Qt3.3.5)

    Quote Originally Posted by vermarajeev View Post
    Is there anything in QTextEdit which can give me the current QPoint position of the cursor.
    Yes, there is, but it isn't a part of public API. QTextEdit can give you a pointer to QTextCursor and that cursor object knows its exact position.

Similar Threads

  1. visible text of textedit
    By regix in forum Qt Programming
    Replies: 3
    Last Post: 26th June 2006, 09:02

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.