当前位置: 首页>>代码示例>>C++>>正文


C++ QTextEdit::setTextCursor方法代码示例

本文整理汇总了C++中QTextEdit::setTextCursor方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextEdit::setTextCursor方法的具体用法?C++ QTextEdit::setTextCursor怎么用?C++ QTextEdit::setTextCursor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QTextEdit的用法示例。


在下文中一共展示了QTextEdit::setTextCursor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: replace

void FindDialog::replace()
{
	QString text = m_find_string->text();
	if (text.isEmpty()) {
		return;
	}

	QTextEdit* document = m_documents->currentDocument()->text();
	QTextCursor cursor = document->textCursor();
	Qt::CaseSensitivity cs = m_ignore_case->isChecked() ? Qt::CaseInsensitive : Qt::CaseSensitive;
	if (!m_regular_expressions->isChecked()) {
		if (QString::compare(cursor.selectedText(), text, cs) == 0) {
			cursor.insertText(m_replace_string->text());
			document->setTextCursor(cursor);
		}
	} else {
		QRegExp regex(text, cs, QRegExp::RegExp2);
		QString match = cursor.selectedText();
		if (regex.exactMatch(match)) {
			match.replace(regex, m_replace_string->text());
			cursor.insertText(match);
			document->setTextCursor(cursor);
		}
	}

	find();
}
开发者ID:barak,项目名称:focuswriter,代码行数:27,代码来源:find_dialog.cpp

示例2: replaceAll

void FindDialog::replaceAll()
{
	QString text = m_find_string->text();
	if (text.isEmpty()) {
		return;
	}

	QTextDocument::FindFlags flags;
	if (!m_ignore_case->isChecked()) {
		flags |= QTextDocument::FindCaseSensitively;
	}
	if (m_whole_words->isChecked()) {
		flags |= QTextDocument::FindWholeWords;
	}

	// Count instances
	int found = 0;
	QTextEdit* document = m_documents->currentDocument()->text();
	QTextCursor cursor = document->textCursor();
	cursor.movePosition(QTextCursor::Start);
	forever {
		cursor = document->document()->find(text, cursor, flags);
		if (!cursor.isNull()) {
			found++;
		} else {
			break;
		}
	}
	if (found) {
		if (QMessageBox::question(this, tr("Question"), tr("Replace %n instance(s)?", "", found), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) {
			return;
		}
	} else {
		QMessageBox::information(this, tr("Sorry"), tr("Phrase not found."));
		return;
	}

	// Replace instances
	QTextCursor start_cursor = document->textCursor();
	forever {
		cursor = document->document()->find(text, cursor, flags);
		if (!cursor.isNull()) {
			cursor.insertText(m_replace_string->text());
			document->setTextCursor(cursor);
		} else {
			break;
		}
	}
	document->setTextCursor(start_cursor);
}
开发者ID:quickhand,项目名称:focuswriter,代码行数:50,代码来源:find_dialog.cpp

示例3: updateTexts

void MainWindow::updateTexts() {
    QObject *sender_obj = QObject::sender();
    QTextEdit *sender = dynamic_cast<QTextEdit*>(sender_obj);
    //QTextCursor cursor = sender->textCursor();
    int oldPos(sender->textCursor().selectionStart());


    ui->bit7TextEdit->blockSignals(true);
    ui->ASCIItextEdit->blockSignals(true);
    ui->UCStextEdit->blockSignals(true);
    ui->UTF8textEdit->blockSignals(true);
    ui->textEdit->blockSignals(true);

    ui->bit7TextEdit->setPlainText(  myString.toBit7() );
    //ui->ASCIItextEdit->setPlainText( myString.toASCII() );
    //ui->UCStextEdit->setPlainText(   myString.toUCS() );
    //hui->UTF8textEdit->setPlainText(  myString.toUTF8() );
    ui->textEdit->setPlainText(      myString.toQString() );

    ui->bit7TextEdit->blockSignals(false);
    ui->ASCIItextEdit->blockSignals(false);
    ui->UCStextEdit->blockSignals(false);
    ui->UTF8textEdit->blockSignals(false);
    ui->textEdit->blockSignals(false);
    //updateAllowed = true;

    //sender->setTextCursor(cursor);
    QTextCursor cursor(sender->textCursor());
    cursor.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor, oldPos);
    sender->setTextCursor(cursor);
}
开发者ID:Visko,项目名称:SMStools,代码行数:31,代码来源:mainwindow.cpp

示例4: find

void FindDialog::find(bool backwards)
{
	QString text = m_find_string->text();
	if (text.isEmpty()) {
		return;
	}

	QTextDocument::FindFlags flags;
	if (!m_ignore_case->isChecked()) {
		flags |= QTextDocument::FindCaseSensitively;
	}
	if (m_whole_words->isChecked()) {
		flags |= QTextDocument::FindWholeWords;
	}
	if (backwards) {
		flags |= QTextDocument::FindBackward;
	}

	QTextEdit* document = m_documents->currentDocument()->text();
	QTextCursor cursor = document->document()->find(text, document->textCursor(), flags);
	if (cursor.isNull()) {
		cursor = document->textCursor();
		cursor.movePosition(!backwards ? QTextCursor::Start : QTextCursor::End);
		cursor = document->document()->find(text, cursor, flags);
	}

	if (!cursor.isNull()) {
		document->setTextCursor(cursor);
	} else {
		QMessageBox::information(this, tr("Sorry"), tr("Phrase not found."));
	}
}
开发者ID:quickhand,项目名称:focuswriter,代码行数:32,代码来源:find_dialog.cpp

示例5: on_insertTitle_clicked

void MainWindow::on_insertTitle_clicked()
{
    QTextEdit *pEdit = textEditor.editor;
    QTextCursor cursor = pEdit->textCursor();

    //set alignment center
    pEdit->setAlignment(Qt::AlignHCenter);
    groupCheck(0);

    //insert title
    cursor.insertText("“    ”学院 2011—2012学年第一学期\n");

    //insert paper info
    cursor.insertText("《           》期末考试试卷(  卷) 考核形式(  卷)\n");

    //set alignment left
    pEdit->setAlignment(Qt::AlignLeft);
    groupCheck(2);

    QFont font = pEdit->font();
    font.setBold(true);
    font.setPointSize(16);
    pEdit->setFont(font);
    pEdit->setTextCursor(cursor);
    pEdit->setFocus();
}
开发者ID:KanagiMiss,项目名称:testassist,代码行数:26,代码来源:mainwindow.cpp

示例6: unwrapSmoke

SEXP
qt_qsetCursorPosition_QTextEdit(SEXP x, SEXP pos)
{
    QTextEdit *te = unwrapSmoke(x, QTextEdit);
    QTextCursor tc = te->textCursor();
    tc.setPosition(asInteger(pos));
    te->setTextCursor(tc);
    return R_NilValue;
}
开发者ID:rforge,项目名称:qtinterfaces,代码行数:9,代码来源:textedit.cpp

示例7: replaceCurrentWord

void QWordCompleter::replaceCurrentWord(QString text)
{
    QTextEdit* textEdit = qobject_cast<QTextEdit*>(widget());
    QTextCursor textCursor = textEdit->textCursor();
    textCursor.movePosition(QTextCursor::StartOfWord);
    textCursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
    if (text == "void") text += " " + name + "() {\n\n}";
    else if (text == "if") text += " ( ) {\n\n} else {\n\n}";
    textCursor.insertText(text);
    textEdit->setTextCursor(textCursor);
}
开发者ID:MrBentCode,项目名称:FlowChart_trainer,代码行数:11,代码来源:qwordcompleter.cpp

示例8: execute

 /*!
    * \class SplitCellCommand
    * \author Anders Fernström
    * \date 2006-04-26
    *
    * \brief Split the cell
    */
  void SplitCellCommand::execute()
  {
    try
    {
      if( document()->getCursor()->currentCell() )
      {
        if( typeid( *document()->getCursor()->currentCell() ) == typeid( TextCell ) ||
          typeid( *document()->getCursor()->currentCell() ) == typeid( InputCell ) )
        {
          // extraxt text
          QTextEdit* editor = document()->getCursor()->currentCell()->textEdit();
          if( editor )
          {
            QTextCursor cursor = editor->textCursor();
            cursor.movePosition( QTextCursor::End, QTextCursor::KeepAnchor );
            QTextDocumentFragment text = cursor.selection();
            cursor.removeSelectedText();

            // add new cell
            if( typeid( *document()->getCursor()->currentCell() ) == typeid( TextCell ) )
            {
              AddCellCommand addcellCommand;
              addcellCommand.setApplication( application() );
              addcellCommand.setDocument( document() );
              addcellCommand.execute();
            }
            else
            {
              // inputcell
              CreateNewCellCommand newcellCommand( "Input" );
              newcellCommand.setApplication( application() );
              newcellCommand.setDocument( document() );
              newcellCommand.execute();
            }

            // add text to new cell
            QTextEdit* newEditor = document()->getCursor()->currentCell()->textEdit();
            QTextCursor newCursor = newEditor->textCursor();
            newCursor.insertFragment( text );
            newCursor.movePosition( QTextCursor::Start );
            newEditor->setTextCursor( newCursor );

            // update document
            document()->setChanged( true );
          }
        }
      }
    }
    catch( exception &e )
    {
      string str = string("SplitCellCommand(), Exception: ") + e.what();
      throw runtime_error( str.c_str() );
    }
  }
开发者ID:cephdon,项目名称:OMNotebook,代码行数:61,代码来源:cellcommands.cpp

示例9:

void	QsvTextOperationsWidget::setTextCursor(QTextCursor c)
{
	QTextEdit *t = qobject_cast<QTextEdit*>(parent());
	if (t) {
		t->setTextCursor(c);
	} else {
		QPlainTextEdit *pt = qobject_cast<QPlainTextEdit*>(parent());
		if (pt) {
			pt->setTextCursor(c);
		}
	}
}
开发者ID:martinribelotta,项目名称:embedded-ide,代码行数:12,代码来源:qsvtextoperationswidget.cpp

示例10: find

bool FindDialog::find() {
    QTextEdit* textEdit = getCurrentTextEdit();
    if (textEdit == NULL) return false;
    int from = textEdit->textCursor().selectionEnd();
    QTextCursor cursor = textEdit->document()->find(ui->findString->text(), from);
    if (!cursor.isNull()) {
        textEdit->setTextCursor(cursor);
        return true;
    }
    else {
        return false;
    }
}
开发者ID:furaga,项目名称:CPUExSolver,代码行数:13,代码来源:finddialog.cpp

示例11: editMenuActivated

    void editMenuActivated(QAction *action)
    {
        QWidget* w = qApp->focusWidget();
        QTextEdit* te = qobject_cast<QTextEdit*>(w);
        QLineEdit* le = qobject_cast<QLineEdit*>(w);

        if (action == selectAction) {
            highlighting = this;
            return;
        }
        highlighting = 0;

        if (action == copyAction) {
            if (te) {
                if (te->hasEditFocus()) {
                    te->copy();
                } else {
                    QTextCursor c = te->textCursor();
                    te->selectAll();
                    te->copy();
                    te->setTextCursor(c);   // reset selection
                }
            } else if (le) {
                if (le->hasEditFocus()) {
                    le->copy();
                } else {
                    qApp->clipboard()->setText(le->text());
                }
            }
        } else if (action == pasteAction) {
            // assumes clipboard is not empty if 'Paste' is able to be
            // activated, otherwise the line/textedit might be cleared
            // without pasting anything back into it
            if (te) {
                if (!te->hasEditFocus())
                    te->clear();
                te->paste();
                if (!te->hasEditFocus()) {
                    te->moveCursor(QTextCursor::Start);
                    te->ensureCursorVisible();
                }
            } else if (le) {
                if (!le->hasEditFocus())
                    le->clear();
                le->paste();
                if (!le->hasEditFocus())
                    le->home(false);
            }
        }
    }
开发者ID:muromec,项目名称:qtopia-ezx,代码行数:50,代码来源:qsoftmenubar.cpp

示例12: 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;
}
开发者ID:m8a,项目名称:uim,代码行数:49,代码来源:qtextutil.cpp

示例13: insertQuestionTypeTitle

void MainWindow::insertQuestionTypeTitle(const QString &title)
{
    QTextEdit *pEdit = textEditor.editor;
    QTextCursor cursor = pEdit->textCursor();

    cursor.insertText(tr("\n"));
    pEdit->setTextCursor(cursor);

    cursor.insertText(title+" ");
    pEdit->setTextCursor(cursor);

    //set font of title and info
    QFont font = pEdit->font();
    QTextCharFormat fmt;
    font.setBold(true);
    font.setPointSize(13);
    fmt.setFont(font);
    cursor.select(QTextCursor::BlockUnderCursor);
    cursor.mergeCharFormat(fmt);

    cursor.select(QTextCursor::WordUnderCursor);
    cursor.insertText("\n");
    pEdit->setTextCursor(cursor);

    //set font of questions
    cursor.insertText(" ");
    font.setBold(false);
    font.setPointSize(10);
    fmt.setFont(font);
    cursor.select(QTextCursor::BlockUnderCursor);
    cursor.mergeCharFormat(fmt);

    cursor.select(QTextCursor::WordUnderCursor);
    cursor.deletePreviousChar();
    pEdit->setTextCursor(cursor);
}
开发者ID:KanagiMiss,项目名称:testassist,代码行数:36,代码来源:mainwindow.cpp

示例14: replace

void FindDialog::replace()
{
	QString text = m_find_string->text();
	if (text.isEmpty()) {
		return;
	}

	QTextEdit* document = m_documents->currentDocument()->text();
	QTextCursor cursor = document->textCursor();
	Qt::CaseSensitivity cs = m_ignore_case->isChecked() ? Qt::CaseInsensitive : Qt::CaseSensitive;
	if (QString::compare(cursor.selectedText(), text, cs) == 0) {
		cursor.insertText(m_replace_string->text());
		document->setTextCursor(cursor);
	}
	find();
}
开发者ID:quickhand,项目名称:focuswriter,代码行数:16,代码来源:find_dialog.cpp

示例15: findCurrent

void VBoxLogSearchPanel::findCurrent (const QString &aSearchString)
{
    mButtonsNextPrev->setEnabled (0, aSearchString.length());
    mButtonsNextPrev->setEnabled (1, aSearchString.length());
    toggleWarning (!aSearchString.length());
    if (aSearchString.length())
        search (true, true);
    else
    {
        QTextEdit *browser = mViewer->currentLogPage();
        if (browser && browser->textCursor().hasSelection())
        {
            QTextCursor cursor = browser->textCursor();
            cursor.setPosition (cursor.anchor());
            browser->setTextCursor (cursor);
        }
    }
}
开发者ID:LastRitter,项目名称:vbox-haiku,代码行数:18,代码来源:VBoxVMLogViewer.cpp


注:本文中的QTextEdit::setTextCursor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。