本文整理汇总了C++中QPlainTextEdit::insertPlainText方法的典型用法代码示例。如果您正苦于以下问题:C++ QPlainTextEdit::insertPlainText方法的具体用法?C++ QPlainTextEdit::insertPlainText怎么用?C++ QPlainTextEdit::insertPlainText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPlainTextEdit
的用法示例。
在下文中一共展示了QPlainTextEdit::insertPlainText方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: insertTextAtLine
//-------------------------------------------------------------------------
void MainWindow::insertTextAtLine(int lineNr, const char* pText)
{
QPlainTextEdit *sourceCode = getCurrentSourceCode();
if (lineNr >= 0)
{
QTextCursor sourceCursor = sourceCode->textCursor();
sourceCursor.setPosition(sourceCode->document()->findBlockByLineNumber(lineNr).position());
sourceCode->setTextCursor(sourceCursor);
}
else
{
sourceCode->moveCursor(QTextCursor::StartOfLine);
}
sourceCode->insertPlainText(QString::fromUtf8(pText));
}
示例2: eventFilter
bool ItemDelegate::eventFilter(QObject *object, QEvent *event)
{
if (object->objectName() == "editor") {
QPlainTextEdit *editor = qobject_cast<QPlainTextEdit*>(object);
if (editor == NULL)
return false;
QEvent::Type type = event->type();
if ( type == QEvent::KeyPress ) {
QKeyEvent *keyevent = static_cast<QKeyEvent *>(event);
switch ( keyevent->key() ) {
case Qt::Key_Enter:
case Qt::Key_Return:
// Commit data on Ctrl+Return or Enter?
if (m_saveOnReturnKey) {
if (keyevent->modifiers() == Qt::ControlModifier) {
editor->insertPlainText("\n");
return true;
} else if (keyevent->modifiers() != Qt::NoModifier) {
return false;
}
} else {
if (keyevent->modifiers() != Qt::ControlModifier)
return false;
}
emit commitData(editor);
emit closeEditor(editor);
return true;
case Qt::Key_S:
// Commit data on Ctrl+S.
if (keyevent->modifiers() != Qt::ControlModifier)
return false;
emit commitData(editor);
emit closeEditor(editor);
return true;
case Qt::Key_F2:
// Commit data on F2.
emit commitData(editor);
emit closeEditor(editor);
return true;
case Qt::Key_Escape:
// Close editor without committing data.
emit closeEditor(editor, QAbstractItemDelegate::RevertModelCache);
return true;
default:
return false;
}
} else if ( type == QEvent::ContextMenu ) {
QAction *act;
QMenu *menu = editor->createStandardContextMenu();
connect( menu, SIGNAL(aboutToHide()), menu, SLOT(deleteLater()) );
menu->setParent(editor);
act = menu->addAction( tr("&Save Item") );
act->setShortcut( QKeySequence(tr("F2, Ctrl+Enter")) );
connect( act, SIGNAL(triggered()), this, SLOT(editorSave()) );
act = menu->addAction( tr("Cancel Editing") );
act->setShortcut( QKeySequence(tr("Escape")) );
connect( act, SIGNAL(triggered()), this, SLOT(editorCancel()) );
QContextMenuEvent *menuEvent = static_cast<QContextMenuEvent *>(event);
menu->popup( menuEvent->globalPos() );
}
} else {
// resize event for items
if (event->type() == QEvent::Resize) {
QResizeEvent *resize = static_cast<QResizeEvent *>(event);
ItemWidget *item = dynamic_cast<ItemWidget *>(object);
if (item != NULL) {
item->widget()->resize(resize->size());
onItemChanged(item);
return true;
}
}
}
return false;
}