本文整理汇总了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);
}
示例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();
}
示例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();
}
}
示例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;
}
示例5: textCursor
void
FormText::clearSelection()
{
QTextCursor c = textCursor();
c.clearSelection();
setTextCursor( c );
}
示例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);
}
示例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);
}
示例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;
}
示例9: clearSelection
void TextEditEx::clearSelection()
{
QTextCursor cur = textCursor();
cur.clearSelection();
setTextCursor(cur);
prev_pos_ = -1;
}
示例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;
}
示例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);
}
}
}
}
}
示例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;
}
}
示例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;
}
示例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;
}
示例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);
}