void ItemWidget::setEditorData(QWidget *editor, const QModelIndex &index) const { QTextEdit *textEdit = qobject_cast<QTextEdit *>(editor); if (textEdit != NULL) { const QString text = index.data(Qt::EditRole).toString(); textEdit->setPlainText(text); textEdit->selectAll(); } }
void ItemWidget::setEditorData(QWidget *editor, const QModelIndex &index) const { QTextEdit *textEdit = qobject_cast<QTextEdit *>(editor); if (textEdit != NULL) { if ( index.data(contentType::hasHtml).toBool() ) { const QString html = index.data(contentType::html).toString(); textEdit->setHtml(html); } else { const QString text = index.data(Qt::EditRole).toString(); textEdit->setPlainText(text); } textEdit->selectAll(); } }
void PluginSpellCheck::slotSpellCheck() { // qDebug() << "Plugin parent : " << parent()->objectName() << " (" << parent()->metaObject()->className() << ")"; // The parent is assumed to be a NotepadPart // Can't use qobject_cast here, we would need NotepadPart to be in a shared library. if (!parent()->inherits("NotepadPart")) { KMessageBox::error(0, QStringLiteral("You just called the spell-check action on a wrong part (not NotepadPart)")); } else { NotepadPart *part = (NotepadPart *) parent(); QTextEdit *widget = qobject_cast<QTextEdit *>(part->widget()); Q_ASSERT(widget); widget->selectAll(); } }
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); } } }
QString QtopiaInputDialog::getMultiLineText(QWidget *parent, const QString &title, const QString &label, QtopiaApplication::InputMethodHint hint, const QString &hintParam, const QString &text, bool *ok) { QTextEdit *te = new QTextEdit; QtopiaApplication::setInputMethodHint(te, hint, hintParam); te->setPlainText(text); te->setFocus(); te->selectAll(); te->setMinimumHeight(100); QtopiaInputDialog dlg(parent, title, label, te); QString result; bool accepted = (QtopiaApplication::execDialog(&dlg) == QDialog::Accepted); if (ok) *ok = accepted; if (accepted) result = te->toPlainText(); return result; }
void highlightMatches(const QString &pattern) { QTextEdit *ed = qobject_cast<QTextEdit *>(m_widget); if (!ed) return; // Clear previous highlights. ed->selectAll(); QTextCursor cur = ed->textCursor(); QTextCharFormat fmt = cur.charFormat(); fmt.setBackground(Qt::transparent); cur.setCharFormat(fmt); // Highlight matches. QTextDocument *doc = ed->document(); QRegExp re(pattern); cur = doc->find(re); int a = cur.position(); while ( !cur.isNull() ) { if ( cur.hasSelection() ) { fmt.setBackground(Qt::yellow); cur.setCharFormat(fmt); } else { cur.movePosition(QTextCursor::NextCharacter); } cur = doc->find(re, cur); int b = cur.position(); if (a == b) { cur.movePosition(QTextCursor::NextCharacter); cur = doc->find(re, cur); b = cur.position(); if (a == b) break; } a = b; } }
// すべて選択 void MainWindow::textEditSelectAll() { QTextEdit* textEdit = getCurrentTextEdit(); if (textEdit == NULL) return; textEdit->selectAll(); }