#include #include #include #include #include #include #include #include class Editor : public QTextEdit { public: Editor() { auto cursor = textCursor(); QTextListFormat fmt; fmt.setStyle(QTextListFormat::ListDecimal); cursor.createList(fmt); cursor.insertText("Line one\nLine two"); }; protected: void keyPressEvent(QKeyEvent* event) { if (event->key() == Qt::Key_F8) { auto cursor = textCursor(); auto list = cursor.currentList(); auto fmt = list->format(); fmt.setIndent(fmt.indent() + 1); cursor.createList(fmt); qDebug().noquote() << toHtml(); } else if (event->key() == Qt::Key_F9) { auto cursor = textCursor(); cursor.insertBlock(); cursor.movePosition(QTextCursor::PreviousBlock); auto list = cursor.currentList(); auto fmt = list->format(); fmt.setIndent(fmt.indent() + 1); auto new_list = cursor.createList(fmt); qDebug().noquote() << toHtml(); cursor.movePosition(QTextCursor::NextBlock); new_list->add(cursor.block()); qDebug().noquote() << toHtml(); } else { QTextEdit::keyPressEvent(event); } } }; int main(int argc, char* argv[]) { QApplication app(argc, argv); Editor editor; editor.show(); return app.exec(); }