Results 1 to 2 of 2

Thread: How to get column number in a line

  1. #1
    Join Date
    Jan 2006
    Posts
    26
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Smile How to get column number in a line

    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!
    There is no secret in the face of the code.

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to get column number in a line

    Quote Originally Posted by showhand
    How can I get column number in a line??
    try

    int QTextCursor:osition () const

    Quote Originally Posted by showhand
    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

    Qt Code:
    1. void textEdit::keyPressEvent(QKeyEvent *e)
    2. {
    3. QTextCursor cursor = textEdit->textCursor();
    4. if(e->key() == Qt::Key_Left){
    5. if(movePositions(QTextCursor::Left)){
    6. column_num_--;
    7. }
    8. }
    9. else if(e->key() == Qt::Key_Right){
    10. if(movePositions(QTextCursor::Right)){
    11. column_num_++;
    12. }
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. count line number in text
    By Alina in forum Qt Programming
    Replies: 2
    Last Post: 18th August 2006, 08:29
  2. QTableView paints too much
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2006, 18:42
  3. QListWidget-problem
    By Sarma in forum Qt Programming
    Replies: 7
    Last Post: 7th April 2006, 18:49
  4. QTextBrowser with line numbers
    By sreedhar in forum Qt Programming
    Replies: 1
    Last Post: 3rd April 2006, 13:23
  5. hidden QListView column suddenly visible
    By edb in forum Qt Programming
    Replies: 10
    Last Post: 27th January 2006, 08:00

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.