本文整理汇总了C++中QTextCursor::select方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextCursor::select方法的具体用法?C++ QTextCursor::select怎么用?C++ QTextCursor::select使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextCursor
的用法示例。
在下文中一共展示了QTextCursor::select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: displayTooltip
void MainWindow::displayTooltip(QMouseEvent *e)
{
static bool isFirstTime = true;
static int selectionStart;
static QString selectedText;
static bool isExisted = false; //мы выделяли существующее в словаре?
bool isExist = false;
int i;
QPoint p = e->pos();
QTextCursor tc = ui->textEdit->cursorForPosition(p);
tc.select(QTextCursor::WordUnderCursor);
if (selectionStart != tc.selectionStart()) {
//проверяем, есть ли слово в словаре
for(i = 0; i < bptr->getListWords().size(); i++)
{
if(!bptr->getListWords().at(i).word.compare(tc.selectedText(), Qt::CaseInsensitive))
{
isExist = true;
break;
}
if(!bptr->getListWords().at(i).word.compare(selectedText, Qt::CaseInsensitive))
{
isExisted = true;
}
}
if (!isFirstTime)
{
QToolTip::hideText(); //скрываем предыдущий тултип
//Надо удалить выделение предыдущего слова
QTextCursor tc(ui->textEdit->document());
tc.setPosition(selectionStart);
tc.select(QTextCursor::WordUnderCursor);
if(isExisted)
tc.insertHtml(QString("<u>" + selectedText + "</b>"));
else
{
tc.insertHtml(QString(selectedText));
}
isExisted = false;
}
selectionStart = tc.selectionStart();
selectedText = tc.selectedText();
if (tc.selectedText().length() > 0 && isExist)
{
// QToolTip::showText(e->globalPos(), bptr->getListWords().at(i).toString(),
// ui->textEdit, ui->textEdit->cursorRect());
QToolTip::showText(e->globalPos(), bptr->getListWords().at(i).toString(),
ui->textEdit, ui->textEdit->cursorRect(tc));
isFirstTime = false;
tc.insertHtml(QString("<b>" + tc.selectedText() + "</b>"));
}
}
}
示例2: createCSVImportView
void CSVImportDialog::createCSVImportView(QString filenamein)
{
QFile file(filenamein);
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
// read file
ui->csvTextEdit->setText(file.readAll());
}
this->setWindowTitle("CSV Import - " + filenamein);
QTextCursor cursor = ui->csvTextEdit->textCursor();
QTextCharFormat format;
cursor.select(QTextCursor::Document);
format.setForeground( QBrush( QColor( "black" ) ) );
format.setFontStrikeOut(false);
cursor.setCharFormat( format );
for(int i=0; i<ui->lineskipSpinBox->value(); i++){
format.setForeground( QBrush( QColor( "red" ) ) );
format.setFontStrikeOut(true);
cursor.movePosition(QTextCursor::Start);
cursor.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor, i);
cursor.select(QTextCursor::LineUnderCursor);
cursor.setCharFormat( format );
}
}
示例3: _clearLine
void TabTerminal::_clearLine()
{
QTextCursor c = this->textCursor();
c.select(QTextCursor::LineUnderCursor);
c.removeSelectedText();
this->insertHtml(_userPrompt);
}
示例4: spellCheck
void TCommandLine::spellCheck()
{
if (!mpHost->mEnableSpellCheck) {
return;
}
QTextCursor oldCursor = textCursor();
QTextCharFormat f;
auto cred = QColor(Qt::red);
f.setUnderlineStyle(QTextCharFormat::SpellCheckUnderline);
f.setUnderlineColor(cred);
QTextCursor c = textCursor();
c.select(QTextCursor::WordUnderCursor);
if (!Hunspell_spell(mpHunspell, c.selectedText().toLatin1().data())) {
f.setFontUnderline(true);
c.setCharFormat(f);
} else {
f.setFontUnderline(false);
c.setCharFormat(f);
}
setTextCursor(c);
f.setFontUnderline(false);
oldCursor.setCharFormat(f);
setTextCursor(oldCursor);
}
示例5: mergeFormatOnWordOrSelection
void DocumentHandler::mergeFormatOnWordOrSelection(const QTextCharFormat &format)
{
QTextCursor cursor = textCursor();
if (!cursor.hasSelection())
cursor.select(QTextCursor::WordUnderCursor);
cursor.mergeCharFormat(format);
}
示例6: mouseReleaseEvent
void DrugInputEdit::mouseReleaseEvent(QMouseEvent *event) {
Q_UNUSED(event);
QTextCursor tc = textCursor();
tc.select(QTextCursor::LineUnderCursor);
QString name = tc.selectedText();
emit drugNameChanged(name);
}
示例7: contextMenuEvent
void MLEdit::contextMenuEvent(QContextMenuEvent* event)
{
QMenu* menu=createStandardContextMenu();
if (!isReadOnly())
{
#ifdef HAVE_HUNSPELL
// Save position so we know which word to replace
myMenuPos = event->pos();
// Get word under cursor
QTextCursor cr = cursorForPosition(myMenuPos);
cr.select(QTextCursor::WordUnderCursor);
QString word = cr.selectedText();
if (!word.isEmpty())
{
// Get spelling suggestions
QStringList suggestions = mySpellChecker->getSuggestions(word);
if (!suggestions.isEmpty())
{
// Add spelling suggestions at the top of the menu
QAction* firstAction = menu->actions().first();
foreach (QString w, suggestions)
{
QAction* a = new QAction(w, menu);
connect(a, SIGNAL(triggered()), SLOT(replaceWord()));
menu->insertAction(firstAction, a);
}
示例8: insertBrace
void RtfCssEditor::insertBrace() {
if (c->widget() != this)
return;
QTextCursor tc = textCursor();
int currentPos = tc.position();
tc.movePosition(QTextCursor::Down);
tc.select(QTextCursor::LineUnderCursor);
if (tc.selectedText().isEmpty() == true) {
tc.setPosition(currentPos);
//if (QTextCursor::NextWord)
tc.insertText("\n \n}");
/*tc.movePosition(QTextCursor::Left);
tc.movePosition(QTextCursor::Left);*/
tc.movePosition(QTextCursor::Left);
tc.movePosition(QTextCursor::Left);
setTextCursor(tc);
QRect cr = cursorRect();
cr.setWidth(c->popup()->sizeHintForColumn(0) + c->popup()->verticalScrollBar()->sizeHint().width());
c->complete(cr); // popup it up!
}
else {
tc.setPosition(currentPos);
tc.insertText("\n ");
}
tc.movePosition(QTextCursor::EndOfWord);
QRect cr = cursorRect();
cr.setWidth(c->popup()->sizeHintForColumn(0) + c->popup()->verticalScrollBar()->sizeHint().width());
c->complete(cr); // popup it up!
}
示例9: mergeFormatOnWordOrSelection
void XYZTextEditor::mergeFormatOnWordOrSelection(const QTextCharFormat &format) {
QTextCursor cursor = m_ui->textEdit->textCursor();
if (!cursor.hasSelection())
cursor.select(QTextCursor::WordUnderCursor);
cursor.mergeCharFormat(format);
m_ui->textEdit->mergeCurrentCharFormat(format);
}
示例10: showAutocompletionMenu
void BAbstractFileType::showAutocompletionMenu(BAbstractCodeEditorDocument *doc, QTextCursor cursor, const QPoint &)
{
if (cursor.isNull())
return;
QCompleter *completer = doc->findChild<QCompleter *>("beqt/completer");
cursor.select(QTextCursor::WordUnderCursor);
if (!cursor.hasSelection()) {
if (completer)
completer->popup()->hide();
return;
}
QList<AutocompletionItem> list = createAutocompletionItemList(doc, cursor);
if (list.isEmpty()) {
if (completer)
completer->popup()->hide();
return;
}
QStandardItemModel *model = doc->findChild<QStandardItemModel *>("beqt/completion_model");
if (!model) {
model = new QStandardItemModel(doc);
model->setObjectName("beqt/completion_model");
model->setColumnCount(1);
}
model->clear();
foreach (const AutocompletionItem &item, list) {
QStandardItem *si = new QStandardItem(item.actionIcon, item.actionText);
si->setData(item.actionToolTip, Qt::ToolTipRole);
si->setData(item.text, Qt::UserRole);
model->appendRow(si);
}
示例11: handleHistory
void ConsoleWidget::handleHistory(bool down)
{
int index;
moveCursor(QTextCursor::End);
QTextCursor cursor = textCursor();
if (m_history.size()==0)
return;
if (down)
m_histIndex--;
else
m_histIndex++;
if (m_histIndex>m_history.size()-1)
m_histIndex = m_history.size()-1;
if (m_histIndex<0)
m_histIndex = 0;
index = m_history.size()-1-m_histIndex;
cursor.select(QTextCursor::LineUnderCursor);
cursor.removeSelectedText();
handleColor();
insertPlainText(m_prompt + m_history[index]);
moveCursor(QTextCursor::End);
}
示例12: showNotepadContextMenu
void Notepad::showNotepadContextMenu(const QPoint &pt)
{
// Set Notepad popup menu
QMenu *menu = ui->notepadTextEdit->createStandardContextMenu();
QTextCursor cur = ui->notepadTextEdit->textCursor();
QAction* first = menu->actions().at(0);
if (cur.hasSelection()) {
// Get selected text
//this->main->add_debug_output("Selected text: " + cur.selectedText());
this->addr = cur.selectedText();
} else {
// Get word under the cursor
cur.select( QTextCursor::WordUnderCursor);
//this->main->add_debug_output("Word: " + cur.selectedText());
this->addr = cur.selectedText();
}
ui->actionDisassmble_bytes->setText( "Disassemble bytes at: " + this->addr);
ui->actionDisassmble_function->setText( "Disassemble function at: " + this->addr);
ui->actionHexdump_bytes->setText( "Hexdump bytes at: " + this->addr);
ui->actionCompact_Hexdump->setText( "Compact Hexdump at: " + this->addr);
ui->actionHexdump_function->setText( "Hexdump function at: " + this->addr);
menu->insertAction(first, ui->actionDisassmble_bytes);
menu->insertAction(first, ui->actionDisassmble_function);
menu->insertAction(first, ui->actionHexdump_bytes);
menu->insertAction(first, ui->actionCompact_Hexdump);
menu->insertAction(first, ui->actionHexdump_function);
menu->insertSeparator(first);
ui->notepadTextEdit->setContextMenuPolicy(Qt::DefaultContextMenu);
menu->exec(ui->notepadTextEdit->mapToGlobal(pt));
delete menu;
ui->notepadTextEdit->setContextMenuPolicy(Qt::CustomContextMenu);
}
示例13: 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();
}
}
示例14: printMessage
void GLFOutputWindow::printMessage(const char* message)
{
static int index = 1;
// Remove the first few lines when the buffer is overflow.
int nlines = _pTextEdit->document()->lineCount();
if (nlines > MAX_NUM_LINES)
{
int deleteNumLines = nlines / 2;
for (int i = 0; i < deleteNumLines; ++i)
{
QTextCursor tc = _pTextEdit->textCursor();
tc.movePosition(QTextCursor::Start);
tc.select(QTextCursor::LineUnderCursor);
tc.removeSelectedText();
}
QTextCursor tc = _pTextEdit->textCursor();
tc.movePosition(QTextCursor::End);
_pTextEdit->setTextCursor(tc);
}
// Insert the new message
char buffer[1024];
sprintf(buffer, "%d: %s", index++, message);
_pTextEdit->insertPlainText(QString(buffer));
// Scroll to the bottom
QScrollBar *sb = _pTextEdit->verticalScrollBar();
sb->setValue(sb->maximum());
}
示例15: eventFilter
bool ChatWindow::eventFilter(QObject* sender, QEvent* event) {
if (sender == ui->messagePlainTextEdit) {
if (event->type() != QEvent::KeyPress) {
return false;
}
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
if ((keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter) &&
(keyEvent->modifiers() & Qt::ShiftModifier) == 0) {
QString messageText = ui->messagePlainTextEdit->document()->toPlainText().trimmed();
if (!messageText.isEmpty()) {
#ifdef HAVE_QXMPP
const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();
QXmppMessage message;
message.setTo(publicChatRoom->jid());
message.setType(QXmppMessage::GroupChat);
message.setBody(messageText);
XmppClient::getInstance().getXMPPClient().sendPacket(message);
#endif // HAVE_QXMPP
QTextCursor cursor = ui->messagePlainTextEdit->textCursor();
cursor.select(QTextCursor::Document);
cursor.removeSelectedText();
}
return true;
}
} else if (event->type() == QEvent::MouseButtonRelease) {
QVariant userVar = sender->property("user");
if (userVar.isValid()) {
AddressManager::getInstance().goToUser(userVar.toString());
return true;
}
}
return QWidget::eventFilter(sender, event);
}