PDA

View Full Version : How to change paragraph number in QTextEdit?



Sarma
10th March 2006, 07:50
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:


if( e->type() == QEvent::MouseButtonDblClick )
{
QMouseEvent *m = (QMouseEvent*) e;
QPoint clickPos = m->pos()+QPoint( (te->geometry().topLeft()) - te->frameGeometry().topLeft()));

int para1= te->paragraphAt(clickPos);
QString line=te->text(para1);

return true;
}


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.

jacek
10th March 2006, 09:33
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.

Sarma
10th March 2006, 09:42
hi jacek,
Its working man. :D Thanks a lot. So, I have added the following step at line5:


clickPos=te->viewportToContents(clickPos);


regards,
Sarma.