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


C++ QTextCursor::clearSelection方法代码示例

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


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

示例1: doTrackBar

void ChatView::doTrackBar()
{
	// save position, because our manipulations could change it
	int scrollbarValue = verticalScrollBar()->value();

	QTextCursor cursor = textCursor();
	cursor.beginEditBlock();
	PsiRichText::Selection selection = PsiRichText::saveSelection(this, cursor);

	//removeTrackBar(cursor);
	if (oldTrackBarPosition) {
		cursor.setPosition(oldTrackBarPosition, QTextCursor::KeepAnchor);
		QTextBlockFormat blockFormat = cursor.blockFormat();
		blockFormat.clearProperty(QTextFormat::BlockTrailingHorizontalRulerWidth);
		cursor.clearSelection();
		cursor.setBlockFormat(blockFormat);
	}

	//addTrackBar(cursor);
	cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
	oldTrackBarPosition = cursor.position();
	QTextBlockFormat blockFormat = cursor.blockFormat();
	blockFormat.setProperty(QTextFormat::BlockTrailingHorizontalRulerWidth, QVariant(true));
	cursor.clearSelection();
	cursor.setBlockFormat(blockFormat);

	PsiRichText::restoreSelection(this, cursor, selection);
	cursor.endEditBlock();
	setTextCursor(cursor);

	verticalScrollBar()->setValue(scrollbarValue);
}
开发者ID:ackbarr,项目名称:psi,代码行数:32,代码来源:chatview_te.cpp

示例2: duplicate_line

/**
 * Duplicates the current line and inserts the copy below the line
 */
void HaiQTextEdit::duplicate_line() {
    QTextCursor cursor = textCursor();
    int pos(cursor.position());
    cursor.beginEditBlock();
    cursor.clearSelection();
    cursor.movePosition(QTextCursor::EndOfLine);
    cursor.select(QTextCursor::LineUnderCursor);
    QTextDocumentFragment text( cursor.selection() );
    cursor.clearSelection();
    cursor.insertText( QString(QChar::LineSeparator) );
    cursor.insertFragment( text );
    cursor.setPosition(pos);
    cursor.endEditBlock();
}
开发者ID:magland,项目名称:sequencetree5,代码行数:17,代码来源:haiqtextedit.cpp

示例3: setTextInteraction

void Label::setTextInteraction(bool on, bool selectAll)
{
    if(on && textInteractionFlags() == Qt::NoTextInteraction)
       {
           // switch on editor mode:
        qDebug() << textInteractionFlags();
           setTextInteractionFlags(Qt::TextEditorInteraction);
           qDebug() << textInteractionFlags();

           // manually do what a mouse click would do else:
           setFocus(Qt::MouseFocusReason); // this gives the item keyboard focus
           setSelected(true); // this ensures that itemChange() gets called when we click out of the item
           if(selectAll) // option to select the whole text (e.g. after creation of the TextItem)
           {
               QTextCursor c = textCursor();
               c.select(QTextCursor::Document);
               setTextCursor(c);
           }
       }
       else if(!on && textInteractionFlags() == Qt::TextEditorInteraction)
       {
           // turn off editor mode:
           setTextInteractionFlags(Qt::NoTextInteraction);
           // deselect text (else it keeps gray shade):
           QTextCursor c = this->textCursor();
           c.clearSelection();
           this->setTextCursor(c);
           clearFocus();
       }
   }
开发者ID:Ndolam,项目名称:Graphic,代码行数:30,代码来源:label.cpp

示例4: getHtml

/**
 * Returns HTML markup for selected text. If no text is selected, returns
 * HTML markup for all text.
 */
QString PsiTextView::getHtml() const
{
	PsiTextView *ptv = (PsiTextView *)this;
	QTextCursor cursor = ptv->textCursor();
	int position = ptv->verticalScrollBar()->value();
	
	bool unselectAll = false;
	if (!hasSelectedText()) {
		ptv->selectAll();
		unselectAll = true;
	}
	
	QMimeData *mime = createMimeDataFromSelection();
	QString result = mime->html();
	delete mime;
	
	// we need to restore original position if selectAll() 
	// was called, because setTextCursor() (which is necessary
	// to clear selection) will move vertical scroll bar
	if (unselectAll) {
		cursor.clearSelection();
		ptv->setTextCursor(cursor);
		ptv->verticalScrollBar()->setValue(position);
	}
	
	return result;
}
开发者ID:sapo,项目名称:sapo-messenger-for-mac,代码行数:31,代码来源:psitextview.cpp

示例5: textCursor

void
FormText::clearSelection()
{
	QTextCursor c = textCursor();
	c.clearSelection();
	setTextCursor( c );
}
开发者ID:igormironchik,项目名称:prototyper,代码行数:7,代码来源:form_text.cpp

示例6: positionTextEditCursorAtEnd

/*
 * Helper method to position the text cursor always in the end of doc
 */
void OutputDialog::positionTextEditCursorAtEnd()
{
  QTextCursor tc = m_textBrowser->textCursor();
  tc.clearSelection();
  tc.movePosition(QTextCursor::End);
  m_textBrowser->setTextCursor(tc);
}
开发者ID:offa,项目名称:octopi,代码行数:10,代码来源:outputdialog.cpp

示例7: focusOutEvent

void ElementTitle::focusOutEvent(QFocusEvent *event)
{
	QGraphicsTextItem::focusOutEvent(event);

	QString htmlNormalizedText = toHtml().remove("\n", Qt::CaseInsensitive);

	setTextInteractionFlags(Qt::NoTextInteraction);

	parentItem()->setSelected(true);

	// Clear selection
	QTextCursor cursor = textCursor();
	cursor.clearSelection();
	setTextCursor(cursor);

	unsetCursor();

	if (mReadOnly)
		return;

	if (mOldText != toPlainText()) {
		QString value = toPlainText();
		if (mBinding == "name")
			static_cast<NodeElement*>(parentItem())->setName(value);
		else
			static_cast<NodeElement*>(parentItem())->setLogicalProperty(mBinding, value);
	}
	setHtml(htmlNormalizedText);
}
开发者ID:ArtemKopylov,项目名称:qreal,代码行数:29,代码来源:elementTitle.cpp

示例8: find

int QScriptDebuggerCodeView::find(const QString &exp, int options)
{
    Q_D(QScriptDebuggerCodeView);
    QPlainTextEdit *ed = (QPlainTextEdit*)d->editor;
    QTextCursor cursor = ed->textCursor();
    if (options & 0x100) {
        // start searching from the beginning of selection
        if (cursor.hasSelection()) {
            int len = cursor.selectedText().length();
            cursor.clearSelection();
            cursor.setPosition(cursor.position() - len);
            ed->setTextCursor(cursor);
        }
        options &= ~0x100;
    }
    int ret = 0;
    if (ed->find(exp, QTextDocument::FindFlags(options))) {
        ret |= 0x1;
    } else {
        QTextCursor curse = cursor;
        curse.movePosition(QTextCursor::Start);
        ed->setTextCursor(curse);
        if (ed->find(exp, QTextDocument::FindFlags(options)))
            ret |= 0x1 | 0x2;
        else
            ed->setTextCursor(cursor);
    }
    return ret;
}
开发者ID:Akheon23,项目名称:chromecast-mirrored-source.vendor,代码行数:29,代码来源:qscriptdebuggercodeview.cpp

示例9: clearSelection

 void TextEditEx::clearSelection()
 {
     QTextCursor cur = textCursor();
     cur.clearSelection();
     setTextCursor(cur);
     prev_pos_ = -1;
 }
开发者ID:13W,项目名称:icq-desktop,代码行数:7,代码来源:TextEditEx.cpp

示例10: textEditToPlainText

QString ChatEdit::textEditToPlainText()
{
	QTextDocument *doc = document();
	QString result;
	result.reserve(doc->characterCount());
	QTextCursor begin(doc);
	QTextCursor end;
	QString specialChar = QChar(QChar::ObjectReplacementCharacter);
	bool first = true;
	while (!begin.atEnd()) {
		end = doc->find(specialChar, begin, QTextDocument::FindCaseSensitively);
		QString postValue;
		bool atEnd = end.isNull();
		if (atEnd) {
			end = QTextCursor(doc);
			QTextBlock block = doc->lastBlock();
			end.setPosition(block.position() + block.length() - 1);
		} else {
			postValue = end.charFormat().toolTip();
		}
		begin.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor,
						   end.position() - begin.position() - (atEnd ? 0 : 1));
		QString selectionText = begin.selection().toPlainText();
		if (!first)
			result += selectionText.midRef(1);
		else
			result += selectionText;
		result += postValue;
		begin = end;
		end.clearSelection();
		first = false;
	}
	return result;
}
开发者ID:akahan,项目名称:qutim,代码行数:34,代码来源:chatedit.cpp

示例11: dragEnterEvent

void QConsoleWidget::dragEnterEvent(QDragEnterEvent *e){
    TP::dragEnterEvent(e);

	if(e->isAccepted()){/*调整选区为可编辑区域*/
		QTextCursor tc = this->textCursor();
		if (tc.hasSelection()) {
			if (tc.selectionStart()>= this->promptEndPos_) {
				return;
			}
			else {
				if (tc.selectionEnd()<= this->promptEndPos_) {
					tc.clearSelection();
					this->setTextCursor(tc);
				}
				else {
					auto se_ = tc.selectionEnd();
					tc.setPosition(this->promptEndPos_);
					tc.setPosition(se_,QTextCursor::KeepAnchor);
					this->setTextCursor(tc);
				}
			}
		}
	}

}
开发者ID:ngzHappy,项目名称:QtLuaConsole,代码行数:25,代码来源:QConsoleWidget.cpp

示例12: handleKeyBackspace

void GenericCodeEditor::handleKeyBackspace(QKeyEvent * event, QTextCursor & textCursor, bool & updateCursor)
{
    if (event->modifiers() & Qt::META) {
        textCursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::KeepAnchor);
        textCursor.removeSelectedText();
    } else {
        if ( !overwriteMode()
             || (textCursor.positionInBlock() == 0)
             || textCursor.hasSelection() ) {
            QPlainTextEdit::keyPressEvent(event);
        } else {
            // in overwrite mode, backspace should insert a space
            textCursor.beginEditBlock();
            textCursor.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor);
            QString selectedText = textCursor.selectedText();
            if (selectedText == QStringLiteral(" ") ||
                selectedText == QStringLiteral("\t") ) {
                textCursor.clearSelection();
            } else {
                textCursor.insertText(QString(QChar(' ')));
                textCursor.movePosition(QTextCursor::PreviousCharacter);
            }
            textCursor.endEditBlock();
        }
        updateCursor = true;
    }
}
开发者ID:ARTisERR0R,项目名称:supercollider,代码行数:27,代码来源:editor.cpp

示例13: editorLostFocus

//! [5]
void GraphicsScene::editorLostFocus(GraphicsTextItem *item)
{
#if 0
    QTextCursor cursor = item->textCursor();
    cursor.clearSelection();
    item->setTextCursor(cursor);
#endif
    //QMessageBox::information(NULL, "info", QString(tr("GraphicsScene::editorLostFocus")));

    // 失去焦点则马上生成带文字的视频
    //
    // 1, 判断是否修改过 umcomplete
    //
    // 2, 如果修改过内容则生成文字视频
    if(item->getChanged())
    {

        //QMessageBox::information(NULL, "info", QString(tr("GraphicsScene::editorLostFocus item: %1")).arg((int)item));
        //emit updatedTextSignal(item->textAttr(), item->toPlainText());
#if 1
        QString qsAss = createTotalAssInfo();
        emit updatedElementsTextSignal(qsAss, item->toPlainText());
#endif
    }
#if 0
    if (item->toPlainText().isEmpty()) {
        removeItem(item);
        item->deleteLater();
    }
#endif
    curtextItem = 0;
}
开发者ID:ginozh,项目名称:my_wmm,代码行数:33,代码来源:videoscene.cpp

示例14: textUnderCursor

QString ScriptEditorWidget::textUnderCursor() const
{
	QString szWord;
	QTextCursor tc = textCursor();
	if(tc.atBlockStart())
		return QString();
	tc.clearSelection();
	tc.movePosition(QTextCursor::StartOfWord,QTextCursor::KeepAnchor);
	if(tc.atBlockStart())
	{
		szWord.append(tc.selectedText());
		tc.movePosition(QTextCursor::EndOfWord,QTextCursor::KeepAnchor);
		szWord.append(tc.selectedText());
		if(tc.atBlockEnd()){
			return szWord;
		}
		tc.movePosition(QTextCursor::NextCharacter,QTextCursor::KeepAnchor);
		szWord.append(tc.selectedText());
		if(szWord.right(1)!=".")
			szWord.chop(1);
		return szWord;
	}

	tc.movePosition(QTextCursor::PreviousCharacter,QTextCursor::KeepAnchor);
	szWord=tc.selectedText();
	if(szWord.left(1)==".")
	{
		tc.movePosition(QTextCursor::StartOfWord);
		tc.movePosition(QTextCursor::PreviousCharacter);
		tc.movePosition(QTextCursor::PreviousWord);
		tc.movePosition(QTextCursor::EndOfWord,QTextCursor::KeepAnchor,1);
		szWord.prepend(tc.selectedText());
	} else szWord.remove(0,1);
	return szWord;
}
开发者ID:philouvb,项目名称:KVIrc,代码行数:35,代码来源:ScriptEditorImplementation.cpp

示例15: setCurrentOption

void MenuMainScreen::setCurrentOption(QGraphicsSimpleTextItem *option) {
	QBrush whiteBrush(Qt::white);
	QBrush yellowBrush(Qt::yellow);

	if (!!_currentOption)
		_currentOption->setBrush(whiteBrush);

	_currentOption = option;
	_currentOption->setBrush(yellowBrush);

	if (option->text() == QString("Character"))
		_textField->setPlainText("View more information about the selected character.");
	else if (option->text() == QString("Equipment"))
		_textField->setPlainText("View or change the equipment the selected character is wearing.");
	else if (option->text() == QString("Abilities"))
		_textField->setPlainText("View the abilities of the selected character.");
	else if (option->text() == QString("Inventory"))
		_textField->setPlainText("View the items collected by the party.");
	else if (option->text() == QString("Exit"))
		_textField->setPlainText("Exit the menu.");

	QFont font("Times", 12, QFont::Bold);
	_textField->setFont(font);

	QTextBlockFormat format;
	format.setAlignment(Qt::AlignLeft);
	QTextCursor cursor = _textField->textCursor();
	cursor.select(QTextCursor::Document);
	cursor.mergeBlockFormat(format);
	cursor.clearSelection();
	_textField->setTextCursor(cursor);
}
开发者ID:juniordiscart,项目名称:RPGMaker,代码行数:32,代码来源:MenuMainScreen.cpp


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