[bugs:#2502] Scintilla Qt API cannot set font's style name
Status: open
Group: Feature_Request
Labels: Qt
Created: Sat Mar 14, 2026 06:26 AM UTC by Gary Wang
Last Updated: Sat Mar 14, 2026 06:26 AM UTC
Owner: nobody
Currently, it seems Scintilla's Qt-based API cannot preserve font style name. By using SCI_STYLESETFONT/ScintillaEdit::styleSetFont(), it seems we can only provide a font family name for PlatQt to use, quoted from PlatQt.cpp:
class FontAndCharacterSet : public Font {
public:
CharacterSet characterSet = CharacterSet::Ansi;
std::unique_ptr<QFont> pfont;
explicit FontAndCharacterSet(const FontParameters &fp) : characterSet(fp.characterSet) {
pfont = std::make_unique<QFont>();
pfont->setStyleStrategy(ChooseStrategy(fp.extraFontFlag));
pfont->setFamily(QString::fromUtf8(fp.faceName));
pfont->setPointSizeF(fp.size);
pfont->setBold(static_cast<int>(fp.weight) > 500);
pfont->setStretch(QStretchFromFontStretch(fp.stretch));
pfont->setItalic(fp.italic);
}
};
Qt's own QFontDialog will offer a font style name selection list for user to select, one might prefer to use a non-default style like "Extended". Currently it seems it's not possible to pass the font style name to PlatQt.
Possible solution: Maybe allow user pass the font style name via the styleSetFont API or store them in fp.faceName splitted with a comma? For example, one might set font to Judou Mono FCM,Extended, and if a comma appears, we split the string and use the 2nd part as font style name?
Let me know if you need any additional information, thanks!
Sent from sourceforge.net because scintill...@googlegroups.com is subscribed to https://sourceforge.net/p/scintilla/bugs/
To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/scintilla/admin/bugs/options. Or, if this is a mailing list, you can unsubscribe from the mailing list.
It seems some fonts might have comma (,) in its font family name, so if we go with the splitter method, maybe we need to use another character as splitter like /.
My current patch here btw:
--- a/qt/ScintillaEditBase/PlatQt.cpp
+++ b/qt/ScintillaEditBase/PlatQt.cpp
@@ -147,7 +147,13 @@ public:
explicit FontAndCharacterSet(const FontParameters &fp) : characterSet(fp.characterSet) {
pfont = std::make_unique<QFont>();
pfont->setStyleStrategy(ChooseStrategy(fp.extraFontFlag));
- pfont->setFamily(QString::fromUtf8(fp.faceName));
+ QString faceName = QString::fromUtf8(fp.faceName);
+ if (faceName.contains('/')) {
+ pfont->setFamily(faceName.section('/', 0, 0));
+ pfont->setStyleName(faceName.section('/', 1, -1));
+ } else {
+ pfont->setFamily(faceName);
+ }
pfont->setPointSizeF(fp.size);
pfont->setBold(static_cast<int>(fp.weight) > 500);
pfont->setStretch(QStretchFromFontStretch(fp.stretch));
[bugs:#2502] Scintilla Qt API cannot set font's style name
Status: open
Group: Feature_Request
Labels: Qt
Created: Sat Mar 14, 2026 06:26 AM UTC by Gary Wang
Last Updated: Sat Mar 14, 2026 07:00 AM UTC
Owner: nobody
What does ,Extended signify here? Is it a tag or variable axis?
[bugs:#2502] Scintilla Qt API cannot set font's style name
Status: open
Group: Feature_Request
Labels: Qt
Created: Sat Mar 14, 2026 06:26 AM UTC by Gary Wang
Last Updated: Sat Mar 14, 2026 07:55 AM UTC
Owner: nobody
It is "Judou Mono FCM Extended", "Judou Mono FCM" is its font family, "Extended" is its style name. Another example is "Source Code Pro Semibold" which "Source Code Pro" is its font family name and "Semibold" is its style name. The comma here as a splitter to allow we know whch part is font family name and which part is style name.
[bugs:#2502] Scintilla Qt API cannot set font's style name
Status: open
Group: Feature_Request
Labels: Qt
Created: Sat Mar 14, 2026 06:26 AM UTC by Gary Wang
Last Updated: Sat Mar 14, 2026 08:13 AM UTC
Owner: nobody
Also see this attachment for a screenshot of QFontDialog, the middle list view is font name selection area which shows all available style names.
For the mentioned Judou font, you can find it here: https://github.com/JudouEco/JudouMono/releases/tag/v2.0.0
Attachments:
[bugs:#2502] Scintilla Qt API cannot set font's style name
Status: open
Group: Feature_Request
Labels: Qt
Created: Sat Mar 14, 2026 06:26 AM UTC by Gary Wang
Last Updated: Sat Mar 14, 2026 08:28 AM UTC
Owner: nobody
I was after the meaning of Extended. That is, why did you choose extended rather than default?
[bugs:#2502] Scintilla Qt API cannot set font's style name
Status: open
Group: Feature_Request
Labels: Qt
Created: Sat Mar 14, 2026 06:26 AM UTC by Gary Wang
Last Updated: Sat Mar 14, 2026 08:32 AM UTC
Owner: nobody
Maybe I still haven't understand the question itself? The end user might choose to use the "Extended" style. The application simply offered a QFontDialog to allow user to select the preferred font, font size, style, etc.
[bugs:#2502] Scintilla Qt API cannot set font's style name
Status: open
Group: Feature_Request
Labels: Qt
Created: Sat Mar 14, 2026 06:26 AM UTC by Gary Wang
Last Updated: Sun Mar 15, 2026 09:59 PM UTC
Owner: nobody
How does the resulting display appearance differ when "Extended" is selected compared to how it appears when "Extended" is not selected?
[bugs:#2502] Scintilla Qt API cannot set font's style name
Status: open
Group: Feature_Request
Labels: Qt
Created: Sat Mar 14, 2026 06:26 AM UTC by Gary Wang
Last Updated: Mon Mar 16, 2026 01:40 AM UTC
Owner: nobody
See the attached screenshot. Beside "Extended", there are "Light Extended" and "Bold Extended" as well. I would also suggest you try it out too simply with a QFontDialog.
I'm not a font expert, to my understanding, a font style seems like a font properties preset.
Attachments:
[bugs:#2502] Scintilla Qt API cannot set font's style name
Status: open
Group: Feature_Request
Labels: Qt
Created: Sat Mar 14, 2026 06:26 AM UTC by Gary Wang
Last Updated: Sat Mar 21, 2026 12:26 AM UTC
Owner: nobody
Some additional context:
If you've downloaded the provided font (JudouMonoFCM), inside the zip file you can see a list of ttf files which is exactly the same font but with different style names. Other fonts also do this as well.
Attachments:
[bugs:#2502] Scintilla Qt API cannot set font's style name
Status: open
Group: Feature_Request
Labels: Qt
Created: Sat Mar 14, 2026 06:26 AM UTC by Gary Wang
Last Updated: Sat Mar 21, 2026 03:32 AM UTC
Owner: nobody
"Extended" here appears to be equivalent to setting the font stretch parameter to greater than the default SC_STRETCH_NORMAL=5 like SC_STRETCH_EXPANDED=7.
Since the effect can be achieved by setting an existing parameter, it is less likely that adding an alternative API is justified. When there are two ways to set a parameter, the interaction between these approaches can be a source of bugs and uncertainty.
[bugs:#2502] Scintilla Qt API cannot set font's style name
Status: open
Group: Feature_Request
Labels: Qt
Created: Sat Mar 14, 2026 06:26 AM UTC by Gary Wang
Last Updated: Sat Mar 21, 2026 03:45 PM UTC
Owner: nobody
"Extended" here appears to be equivalent to setting the font stretch parameter to greater than the default SC_STRETCH_NORMAL=5 like SC_STRETCH_EXPANDED=7.
Well, style name works like a "preset", developers does not know the actual stretch number, different font might offer different stretch value using the same style name, or even using a different style name. Actually, we cannot even know the style name is for the stretch font property since the name itself can be anything...
it is less likely that adding an alternative API is justified.
https://sourceforge.net/p/scintilla/bugs/2502/#2cf7 the patch I currently use doesn't add any extra API btw
[bugs:#2502] Scintilla Qt API cannot set font's style name
Status: open
Group: Feature_Request
Labels: Qt
Created: Sat Mar 14, 2026 06:26 AM UTC by Gary Wang
Last Updated: Wed Apr 01, 2026 09:36 PM UTC
Owner: nobody
For example, to select the font we provided above (Judou Mono FCM), if we use QFontDialog::getFont() and select the same font but different style name, the output of the following code would be:
// Button to open the font dialog
QPushButton *fontButton = new QPushButton("Select Font", &window);
QObject::connect(fontButton, &QPushButton::clicked, [&]() {
bool ok;
// Open the font dialog
QFont font = QFontDialog::getFont(&ok, label->font(), &window, "Pick a font");
if (ok) {
// If the user clicks OK, set the label's font to the selected font
qDebug() << font << font.stretch();
label->setFont(font);
}
// If the user clicks Cancel, the original font is retained
});
QFont(Judou Mono FCM,12,-1,5,400,0,0,0,0,0,0,0,0,0,0,1,Extended) 0
QFont(Judou Mono FCM,12,-1,5,400,0,0,0,0,0,0,0,0,0,0,1,Regular) 0
Note that both stretch() values are the vary same value which is 0.
[bugs:#2502] Scintilla Qt API cannot set font's style name
Status: open
Group: Feature_Request
Labels: Qt
Created: Sat Mar 14, 2026 06:26 AM UTC by Gary Wang
Last Updated: Thu Apr 02, 2026 03:27 AM UTC
Owner: nobody