PDA

View Full Version : How to get column number in a line



showhand
30th August 2006, 08:35
Hi~How can I get column number in a line??I used QTextCursor movePositions(QTextCursor::Left),movePositions(QTe xtCursor::Right).But there comes a problem!
when i press left button , the return value of movePositions(QTextCursor::Right) is true.
my code is
void textEdit::keyPressEvent(QKeyEvent *e)
{
QTextCursor cursor = textEdit->textCursor();
if(movePositions(QTextCursor::Left))
column_num_--;
if(movePositions(QTextCursor::Right))
column_num_++;
}
please help me ~~~~Thx!

munna
30th August 2006, 09:42
How can I get column number in a line??

try

int QTextCursor::position () const


I used QTextCursor movePositions(QTextCursor::Left),movePositions(QTe xtCursor::Right).But there comes a problem!
when i press left button , the return value of movePositions(QTextCursor::Right) is true.

Shouldn't your code be something like



void textEdit::keyPressEvent(QKeyEvent *e)
{
QTextCursor cursor = textEdit->textCursor();
if(e->key() == Qt::Key_Left){
if(movePositions(QTextCursor::Left)){
column_num_--;
}
}
else if(e->key() == Qt::Key_Right){
if(movePositions(QTextCursor::Right)){
column_num_++;
}
}
}