Qtでフォントのコンボボックスって?

#include <QFontComboBox> #include <QLabel> #include <QVBoxLayout> QFontComboBox *fontBox = new QFontComboBox(this); QLabel *label = new QLabel("サンプルテキスト", this); connect(fontBox, &QFontComboBox::currentFontChanged, this, [=](const QFont &font){ label->setFont(font); }); QVBoxLayout *layout = new QVBoxLayout(this); layout->addWidget(fontBox); layout->addWidget(label); setLayout(layout);

2026年1月25日

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日