本文整理汇总了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();
}
示例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);
}
示例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);
}
示例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."));
}
}
示例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();
}
示例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;
}
示例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);
}
示例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() );
}
}
示例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);
}
}
}
示例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;
}
}
示例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);
}
}
}
示例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;
}
示例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);
}
示例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();
}
示例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);
}
}
}