Results 1 to 3 of 3

Thread: How to change paragraph number in QTextEdit?

  1. #1
    Join Date
    Mar 2006
    Location
    Hyderabad
    Posts
    69
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default How to change paragraph number in QTextEdit?

    Hi,
    I have posted a thread previously on MouseButtonDblClick event. I have asked how to get the text at the position where the mouse is doubleclicked. I have written the code as:
    Qt Code:
    1. if( e->type() == QEvent::MouseButtonDblClick )
    2. {
    3. QPoint clickPos = m->pos()+QPoint( (te->geometry().topLeft()) - te->frameGeometry().topLeft()));
    4.  
    5. int para1= te->paragraphAt(clickPos);
    6. QString line=te->text(para1);
    7.  
    8. return true;
    9. }
    To copy to clipboard, switch view to plain text mode 

    But now the problem is, when the scrollbar is dragged for a large file, and when mouse is clicked on a line, it is taking the para1 as the line number in the current visible area. That means, if the capacity of the visible region of the textedit is 10 lines, at any time(even when scrollbar is dragged to middle of a large file) the variable para1 is holding the values from 1-10 because of which, the variable "line" is taking only those lines.
    So, please take time to understand my problem ( as I might not put it in correct way ) and give me a good solution

    Thanks a lot,
    Sarma.
    Last edited by Sarma; 10th March 2006 at 09:32.

  2. #2
    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: How to change paragraph number in QTextEdit?

    Quote Originally Posted by Sarma
    That means, if the capacity of the visible region of the textedit is 10 lines, at any time(even when scrollbar is dragged to middle of a large file) the variable para1 is holding the values from 1-10 because of which, the variable "line" is taking only those lines.
    As the docs say:
    int QTextEdit::paragraphAt ( const QPoint & pos ) const
    Returns the paragraph which is at position pos (in contents coordinates).
    You must first translate your mouse position (which is in vieport coordinates) to contents coordinates. Use QScrollView::viewportToContents() method.

  3. #3
    Join Date
    Mar 2006
    Location
    Hyderabad
    Posts
    69
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: How to change paragraph number in QTextEdit?

    hi jacek,
    Its working man. Thanks a lot. So, I have added the following step at line5:
    Qt Code:
    1. clickPos=te->viewportToContents(clickPos);
    To copy to clipboard, switch view to plain text mode 

    regards,
    Sarma.

Similar Threads

  1. how can I find number of lines in QTextedit ?
    By newplayer in forum Newbie
    Replies: 10
    Last Post: 14th August 2008, 23:02
  2. Change margin on QTextEdit print()
    By Dii in forum Qt Programming
    Replies: 2
    Last Post: 20th May 2008, 22:45
  3. Line Number - QTextEdit...???
    By deepusrp in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2007, 16:34
  4. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  5. Replies: 2
    Last Post: 9th March 2007, 23:19

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.