0

I expect this code should work but it doesn't

QTextCursor cursor = textEdit->textCursor();
cursor = QTextCursor(cursor.currentFrame());
cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
textEdit->setTextCursor(cursor);
textEdit->copy(); // Here I got only text from current cell, not a table
tmporaries
  • 1,523
  • 8
  • 25
  • 39

1 Answers1

1

QTextTable cells in a QTextEdit or QTextDocument are represented by a QTextBlock themselves.

Your example code is indeed moving the position of the cursor to the end of the current block which is just the end of the contents of the cell.

In order to select the entire contents of the table you need to select all the cells.

This should work:

    cursor.movePosition( QTextCursor::Start);

    while( cursor.movePosition( QTextCursor::NextCell, QTextCursor::KeepAnchor ) ){
        //...add break condition as failsafe after n iterations?
    }

Note you can query the selection using:

cursor.selectedText();
dr_g
  • 1,179
  • 7
  • 10