本文整理汇总了C++中QTextEdit::textCursor方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextEdit::textCursor方法的具体用法?C++ QTextEdit::textCursor怎么用?C++ QTextEdit::textCursor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextEdit
的用法示例。
在下文中一共展示了QTextEdit::textCursor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: flush
void flush(void) {
QTextBlockFormat bf = editor->textCursor().blockFormat();
bf.setBottomMargin(0);
editor->textCursor().setBlockFormat(bf);
editor->append(buffer);
buffer.clear();
}
示例2: 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."));
}
}
示例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: 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() );
}
}
示例5: overflow
virtual int overflow(int v = std::char_traits<char>::eof()) {
if (v == '\n') {
QTextBlockFormat bf = editor->textCursor().blockFormat();
bf.setBottomMargin(0);
editor->textCursor().setBlockFormat(bf);
editor->append(buffer);
buffer.clear();
} else {
buffer += (char)v;
}
return v;
}
示例6: 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);
}
示例7: replaceAll
void FindDialog::replaceAll()
{
QString text = m_find_string->text();
if (text.isEmpty()) {
return;
}
QRegExp regex(text, !m_ignore_case->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive, QRegExp::RegExp2);
QTextDocument::FindFlags flags;
if (!m_ignore_case->isChecked()) {
flags |= QTextDocument::FindCaseSensitively;
}
if (m_whole_words->isChecked() && !m_regular_expressions->isChecked()) {
flags |= QTextDocument::FindWholeWords;
}
// Count instances
int found = 0;
QTextEdit* document = m_documents->currentDocument()->text();
QTextCursor cursor = document->textCursor();
cursor.movePosition(QTextCursor::Start);
if (!m_regular_expressions->isChecked()) {
forever {
cursor = document->document()->find(text, cursor, flags);
if (!cursor.isNull()) {
found++;
} else {
break;
}
}
} else {
示例8: 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();
}
示例9: textCursor
QTextCursor QTextEditProto::textCursor() const
{
QTextEdit *item = qscriptvalue_cast<QTextEdit*>(thisObject());
if (item)
return item->textCursor();
return QTextCursor();
}
示例10: textCursor
int TextEdit::textCursor(lua_State * L) // const : QTextCursor
{
QTextEdit* obj = ObjectHelper<QTextEdit>::check( L, 1);
QTextCursor* res = ValueInstaller2<QTextCursor>::create( L );
*res = obj->textCursor();
return 1;
}
示例11: 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();
}
示例12: getSetCheck
// Testing get/set functions
void tst_QTextObject::getSetCheck()
{
QTextEdit edit;
QTextFrame obj1(edit.document());
// QTextFrameLayoutData * QTextFrame::layoutData()
// void QTextFrame::setLayoutData(QTextFrameLayoutData *)
QTextFrameLayoutData *var1 = new QTextFrameLayoutData;
obj1.setLayoutData(var1);
QCOMPARE(var1, obj1.layoutData());
obj1.setLayoutData((QTextFrameLayoutData *)0);
QCOMPARE((QTextFrameLayoutData *)0, obj1.layoutData());
// delete var1; // No delete, since QTextFrame takes ownership
QTextBlock obj2 = edit.textCursor().block();
// QTextBlockUserData * QTextBlock::userData()
// void QTextBlock::setUserData(QTextBlockUserData *)
QTextBlockUserData *var2 = new QTextBlockUserData;
obj2.setUserData(var2);
QCOMPARE(var2, obj2.userData());
obj2.setUserData((QTextBlockUserData *)0);
QCOMPARE((QTextBlockUserData *)0, obj2.userData());
// int QTextBlock::userState()
// void QTextBlock::setUserState(int)
obj2.setUserState(0);
QCOMPARE(0, obj2.userState());
obj2.setUserState(INT_MIN);
QCOMPARE(INT_MIN, obj2.userState());
obj2.setUserState(INT_MAX);
QCOMPARE(INT_MAX, obj2.userState());
}
示例13: mergeFormatOnWordOrSelection
void MainWindow::mergeFormatOnWordOrSelection(const QTextCharFormat& format)
{
QTextEdit *pEdit = textEditor.editor;
QTextCursor cursor = pEdit->textCursor();
if (!cursor.hasSelection())
cursor.select(QTextCursor::WordUnderCursor);
cursor.mergeCharFormat(format);
pEdit->mergeCurrentCharFormat(format);
}
示例14: 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;
}
示例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);
}
}
}