Qt6のテキストカーソル移動のイベントは?

QTextEdit / QPlainTextEdit connect(textEdit, &QTextEdit::cursorPositionChanged, this, [](){ qDebug() << "カーソルが移動しました"; }); QLineEdit connect(lineEdit, &QLineEdit::cursorPositionChanged, this, [](int oldPos, int newPos){ qDebug() << oldPos << "->" << newPos; });

2026年1月29日

QtのQTextEditで選択中のテキストの色やフォントを変更するには?

A. テキストの色を変更 QTextCursor cursor = ui->textEdit->textCursor(); if (cursor.hasSelection()) { QTextCharFormat fmt; fmt.setForeground(Qt::red); // 文字色 cursor.mergeCharFormat(fmt); } B. フォントを変更 QTextCharFormat fmt; fmt.setFontFamily("Consolas"); fmt.setFontPointSize(14); fmt.setFontWeight(QFont::Bold); fmt.setFontItalic(true); cursor.mergeCharFormat(fmt);

2026年1月25日