Qt如何将所选内容向上移动到一行
我有麻烦了。我的代码是:Qt如何将所选内容向上移动到一行,qt,qplaintextedit,Qt,Qplaintextedit,我有麻烦了。我的代码是: void TextEditor::moveToLineUp() { QTextCursor cur = textCursor(); if(cur.hasSelection()) { int start = cur.selectionStart(); int end = cur.selectionEnd(); QTextBlock startBlock = document()->findBlock(
void TextEditor::moveToLineUp()
{
QTextCursor cur = textCursor();
if(cur.hasSelection()) {
int start = cur.selectionStart();
int end = cur.selectionEnd();
QTextBlock startBlock = document()->findBlock(start);
QTextBlock endBlock = document()->findBlock(end);
cur.setPosition(startBlock.position());
cur.setPosition(endBlock.position()+endBlock.length(), QTextCursor::KeepAnchor);
} else {
// I'll fill it later
}
// ??? I don't know how not to write remove action in undo stack
QString text = cur.selectedText();
cur.removeSelectedText();
QTextCursor ncur(cur.block().previous());
ncur.insertText(text);
}
当用户选择一些文本并点击“排队”按钮时,调用此函数。
有选择的每一行都应该向上移动一行。但在撤销堆栈之后,必须执行以下步骤:删除文本和粘贴文本。我该怎么办?我想让它一步操作简单。你检查过qtcreator在升档时是如何操作的吗?没有。那是个好主意