本文整理汇总了C++中QTextCursor::deleteChar方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextCursor::deleteChar方法的具体用法?C++ QTextCursor::deleteChar怎么用?C++ QTextCursor::deleteChar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextCursor
的用法示例。
在下文中一共展示了QTextCursor::deleteChar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: reg
QTextDocument *Exporter::prepareTextDoc(QTextDocument *textDoc)
{
QTextDocument *textDocument = textDoc->clone(this);
// textDocument->setDefaultStyleSheet("p, li { white-space: pre-wrap; } p{line-height: 2em; font-family:'Liberation Serif'; font-size:19pt;margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:72px;}");
//cut blank spaces at the begining and end :
QTextCursor *tCursor = new QTextCursor(textDocument);
tCursor->movePosition(QTextCursor::Start, QTextCursor::MoveAnchor,1);
tCursor->movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor,1);
while(tCursor->selectedText() == " "){
tCursor->deleteChar();
tCursor->movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor,1);
}
tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1);
tCursor->movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor,1);
while(tCursor->selectedText() == " "){
tCursor->deleteChar();
tCursor->movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor,1);
}
//set text config :
QTextBlockFormat blockFormat;
// blockFormat.setBottomMargin(0);
// blockFormat.setTopMargin(0);
// blockFormat.setTextIndent(72);
blockFormat.setLineHeight(200, QTextBlockFormat::ProportionalHeight);
blockFormat.setAlignment(Qt::AlignJustify);
// QTextCharFormat charFormat;
// charFormat.setFontPointSize(12);
// charFormat.setFontFamily("Courrier");
tCursor->select(QTextCursor::Document);
tCursor->mergeBlockFormat(blockFormat);
// tCursor->mergeBlockCharFormat(charFormat);
QRegExp reg("-qt-paragraph-type:.*;|margin-top:.*;|margin-bottom:.*;|margin-left:.*;|margin-right:.*;|-qt-block-indent:.*;|text-indent:.*;|font-family:.*;|font-size:.*;");
reg.setMinimal(true);
textDocument->setHtml(textDocument->toHtml().remove(reg));
return textDocument;
}
示例2: deleteLine
void CodeEditor::deleteLine(){
QTextCursor selection = getSelectedLines();
selection.beginEditBlock();
selection.removeSelectedText();
selection.deleteChar();
selection.endEditBlock();
}
示例3: autoBackspace
bool AutoCompleter::autoBackspace(QTextCursor &cursor)
{
m_allowSkippingOfBlockEnd = false;
if (!m_autoParenthesesEnabled)
return false;
int pos = cursor.position();
if (pos == 0)
return false;
QTextCursor c = cursor;
c.setPosition(pos - 1);
QTextDocument *doc = cursor.document();
const QChar lookAhead = doc->characterAt(pos);
const QChar lookBehind = doc->characterAt(pos - 1);
const QChar lookFurtherBehind = doc->characterAt(pos - 2);
const QChar character = lookBehind;
if (character == QLatin1Char('(') || character == QLatin1Char('[')) {
QTextCursor tmp = cursor;
TextBlockUserData::findPreviousBlockOpenParenthesis(&tmp);
int blockStart = tmp.isNull() ? 0 : tmp.position();
tmp = cursor;
TextBlockUserData::findNextBlockClosingParenthesis(&tmp);
int blockEnd = tmp.isNull() ? (cursor.document()->characterCount()-1) : tmp.position();
QChar openChar = character;
QChar closeChar = (character == QLatin1Char('(')) ? QLatin1Char(')') : QLatin1Char(']');
int errors = 0;
int stillopen = 0;
countBrackets(cursor, blockStart, blockEnd, openChar, closeChar, &errors, &stillopen);
int errorsBeforeDeletion = errors + stillopen;
errors = 0;
stillopen = 0;
countBrackets(cursor, blockStart, pos - 1, openChar, closeChar, &errors, &stillopen);
countBrackets(cursor, pos, blockEnd, openChar, closeChar, &errors, &stillopen);
int errorsAfterDeletion = errors + stillopen;
if (errorsAfterDeletion < errorsBeforeDeletion)
return false; // insertion fixes parentheses or bracket errors, do not auto complete
}
// ### this code needs to be generalized
if ((lookBehind == QLatin1Char('(') && lookAhead == QLatin1Char(')'))
|| (lookBehind == QLatin1Char('[') && lookAhead == QLatin1Char(']'))
|| (lookBehind == QLatin1Char('"') && lookAhead == QLatin1Char('"')
&& lookFurtherBehind != QLatin1Char('\\'))
|| (lookBehind == QLatin1Char('\'') && lookAhead == QLatin1Char('\'')
&& lookFurtherBehind != QLatin1Char('\\'))) {
if (! isInComment(c)) {
cursor.beginEditBlock();
cursor.deleteChar();
cursor.deletePreviousChar();
cursor.endEditBlock();
return true;
}
}
return false;
}
示例4: removeMatchingTokens
bool ScCodeEditor::removeMatchingTokens()
{
QTextCursor cursor = textCursor();
QTextDocument *document = cursor.document();
int cursorPosition = cursor.position();
if (cursorPosition == 0)
return false;
QChar previousChar = document->characterAt(cursorPosition-1);
QChar nextChar;
if (previousChar == '{')
nextChar = '}';
else if (previousChar == '[')
nextChar = ']';
else if (previousChar == '(')
nextChar = ')';
else if (previousChar == '\'' || previousChar == '"')
nextChar = previousChar;
else
return false;
if (document->characterAt(cursorPosition) != nextChar)
return false;
cursor.beginEditBlock();
cursor.deletePreviousChar();
cursor.deleteChar();
cursor.endEditBlock();
setTextCursor(cursor);
return true;
}
示例5: insertCompletion
void CodeEditor::insertCompletion(const QString& completion){
if (completer_->widget() != this){
return;
}
QTextCursor tc = textCursor();
//Delete the characters that the user has entered as it might be in
//wrong case, and insert entire completion word.
tc.movePosition(QTextCursor::StartOfWord);
int toDelete = completer_->completionPrefix().length();
for(int i=0;i<toDelete;i++){
tc.deleteChar();
}
tc.insertText(completion);
setTextCursor(tc);
/*
//original code, insert only missing characters and keep the characters
//the user has already entered.
int extra = completion.length() - completer_->completionPrefix().length();
tc.movePosition(QTextCursor::Left);
tc.movePosition(QTextCursor::EndOfWord);
tc.insertText(completion.right(extra));
setTextCursor(tc);
*/
}
示例6: getTextDocument
void QsvTextOperationsWidget::on_replaceOldText_returnPressed()
{
if (QApplication::keyboardModifiers().testFlag(Qt::ControlModifier) ||
QApplication::keyboardModifiers().testFlag(Qt::AltModifier) ||
QApplication::keyboardModifiers().testFlag(Qt::ShiftModifier) ) {
on_replaceAll_clicked();
showReplace();
return;
}
QTextCursor c = m_searchCursor;
QTextDocument *doc = getTextDocument();
if (!doc){
qDebug("%s:%d - no document found, using a wrong class? wrong parent?", __FILE__,__LINE__);
return;
}
c = doc->find( replaceFormUi->findText->text(), c, getReplaceFlags() );
if (c.isNull())
return;
int start = c.selectionStart();
int end = c.selectionEnd();
c.beginEditBlock();
c.deleteChar();
c.insertText( replaceFormUi->replaceText->text() );
c.setPosition(start,QTextCursor::KeepAnchor);
c.setPosition(end ,QTextCursor::MoveAnchor);
c.endEditBlock();
setTextCursor( c );
// is there any other apperance of this text?
m_searchCursor = c;
updateReplaceInput();
}
示例7: textChangeEvent
void TextProcessor::textChangeEvent() {
if (autoInsertion_)
return;
QTextCursor c = edit_->textCursor();
if (c.atBlockStart()) {
QTextBlock bl = c.block();
QTextBlock prevBl = bl.previous();
if (bl.isValid() && prevBl.isValid()) {
// ensure that cursor was moved from the previous row
if (lastRow_ - 1 != preLastRow_)
return;
QString text = bl.text();
QString prevText = prevBl.text();
if (/*text.isEmpty() &&*/ !prevText.isEmpty()) {
int lineBeginIndex = prevText.indexOf(QRegExp("[^ \t]"));
QString lineBegin = prevText.left(lineBeginIndex);
autoInsertion_ = true;
while (bl.text().startsWith('\t') || bl.text().startsWith(' ')) {
c.deleteChar();
}
c.insertText(lineBegin);
autoInsertion_ = false;
}
}
}
}
示例8: QTextCursor
QTextDocument *Exporter::prepareNoteDoc(QTextDocument *noteDoc)
{
QTextDocument *textDocument = noteDoc->clone(this);
//cut blank spaces at the begining and end :
QTextCursor *tCursor = new QTextCursor(textDocument);
tCursor->movePosition(QTextCursor::Start, QTextCursor::MoveAnchor,1);
tCursor->movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor,1);
while(tCursor->selectedText() == " "){
tCursor->deleteChar();
tCursor->movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor,1);
}
tCursor->movePosition(QTextCursor::End, QTextCursor::MoveAnchor,1);
tCursor->movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor,1);
while(tCursor->selectedText() == " "){
tCursor->deleteChar();
tCursor->movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor,1);
}
//set text config :
QTextBlockFormat blockFormat;
blockFormat.setBottomMargin(0);
blockFormat.setTopMargin(0);
blockFormat.setTextIndent(72);
blockFormat.setLineHeight(200, QTextBlockFormat::ProportionalHeight);
blockFormat.setAlignment(Qt::AlignJustify);
QTextCharFormat charFormat;
charFormat.setFontPointSize(12);
charFormat.setFontFamily("Courrier");
tCursor->select(QTextCursor::Document);
tCursor->mergeBlockCharFormat(charFormat);
tCursor->mergeBlockFormat(blockFormat);
return textDocument;
}
示例9: textCursor
void
SimpleRichTextEdit::deleteText()
{
QTextCursor cursor = textCursor();
if(cursor.hasSelection())
cursor.removeSelectedText();
else
cursor.deleteChar();
}
示例10: deleteCurrentLine
QTextCursor CodeEditor::deleteCurrentLine()
{
QTextCursor currentPos = textCursor();
textCursor().beginEditBlock();
currentPos.select(QTextCursor::BlockUnderCursor);
if (currentPos.selectedText() == ""){
if (currentPos.selectionStart() == 0){
currentPos.deleteChar();
}else{
currentPos.deletePreviousChar();
}
currentPos.removeSelectedText();
}
else{
currentPos.removeSelectedText();
if (currentPos.selectionStart() == 0)
currentPos.deleteChar();
}
return currentPos;
}
示例11: _DeleteCurrentLine
void CCodeEditor::_DeleteCurrentLine()
{
QTextCursor currentCursor = this->textCursor();
currentCursor.select(QTextCursor::BlockUnderCursor);
currentCursor.removeSelectedText();
++m_textChangeTime;
if (currentCursor.atStart())
{
currentCursor.deleteChar();
++m_textChangeTime;
}
}
示例12: sCorrectWord
void XTextEdit::sCorrectWord()
{
QAction *action = qobject_cast<QAction *>(sender());
if (action)
{
QString replacement = action->text();
QTextCursor cursor = cursorForPosition(_lastPos);
cursor.select(QTextCursor::WordUnderCursor);
cursor.deleteChar();
cursor.insertText(replacement);
_highlighter->rehighlight();
}
}
示例13: setHtml
void ChatMessageArea::setHtml(const QString& html) {
// Create format with updated line height
QTextBlockFormat format;
format.setLineHeight(CHAT_MESSAGE_LINE_HEIGHT, QTextBlockFormat::ProportionalHeight);
// Possibly a bug in QT, the format won't take effect if `insertHtml` is used first. Inserting a space and deleting
// it after ensures the format is applied.
QTextCursor cursor = textCursor();
cursor.setBlockFormat(format);
cursor.insertText(" ");
cursor.insertHtml(html);
cursor.setPosition(0);
cursor.deleteChar();
}
示例14: delete_current_line
/**
* Deletes the current line
*/
void HaiQTextEdit::delete_current_line() {
QTextCursor cursor = textCursor();
cursor.beginEditBlock();
cursor.clearSelection();
cursor.movePosition(QTextCursor::StartOfLine);
int pos(cursor.position());
cursor.select(QTextCursor::LineUnderCursor);
// remove line (and line feed char)
cursor.removeSelectedText();
cursor.deleteChar();
// goto start of next line
cursor.setPosition(pos);
cursor.endEditBlock();
}
示例15: if
int
QUimTextUtil::deleteSelectionTextInQTextEdit( enum UTextOrigin origin,
int former_req_len,
int latter_req_len )
{
QTextEdit *edit = static_cast<QTextEdit *>( mWidget );
QTextCursor cursor = edit->textCursor();
if ( ! cursor.hasSelection() )
return -1;
bool cursor_at_beginning = false;
int current = cursor.position();
int start = cursor.selectionStart();
if ( current == start )
cursor_at_beginning = true;
QString text = cursor.selectedText();
int len = text.length();
int end = start + len;
if ( origin == UTextOrigin_Beginning ||
( origin == UTextOrigin_Cursor && cursor_at_beginning ) ) {
if ( latter_req_len >= 0 ) {
if ( len > latter_req_len )
end = start + latter_req_len;
} else {
if (! ( ~latter_req_len
& ( ~UTextExtent_Line | ~UTextExtent_Full ) ) )
return -1;
}
} else if ( origin == UTextOrigin_End ||
( origin == UTextOrigin_Cursor && !cursor_at_beginning ) ) {
if ( former_req_len >= 0 ) {
if ( len > former_req_len )
start = end - former_req_len;
} else {
if (! ( ~former_req_len
& ( ~UTextExtent_Line | ~UTextExtent_Full ) ) )
return -1;
}
} else {
return -1;
}
cursor.setPosition( start );
cursor.setPosition( end, QTextCursor::KeepAnchor );
edit->setTextCursor( cursor );
cursor.deleteChar();
return 0;
}