Draft: add font name dropdown to preferences (#20400)

Fixes #20330.
This commit is contained in:
Roy-043
2025-03-27 13:11:47 +01:00
committed by GitHub
parent 22b1f9b297
commit 51f4917c24
2 changed files with 47 additions and 18 deletions

View File

@@ -75,22 +75,20 @@ in the Annotation scale widget. If the scale is 1:100 the multiplier is 100.</st
<item row="0" column="0">
<widget class="QLabel" name="label_textfont">
<property name="text">
<string>Font name or family</string>
<string>Font name</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="Gui::PrefLineEdit" name="lineEdit_textfont">
<widget class="Gui::PrefFontBox" name="fontBox_textfont">
<property name="minimumSize">
<size>
<width>280</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>The default font for texts, dimensions and labels. It can be a font name such
as &quot;Arial&quot;, a style such as &quot;sans&quot;, &quot;serif&quot; or &quot;mono&quot;, or a family such as
&quot;Arial,Helvetica,sans&quot;, or a name with a style such as &quot;Arial:Bold&quot;.</string>
</property>
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string>Internal font</string>
<string>The default font for texts, dimensions and labels</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>textfont</cstring>
@@ -100,6 +98,13 @@ as &quot;Arial&quot;, a style such as &quot;sans&quot;, &quot;serif&quot; or &qu
</property>
</widget>
</item>
<item row="0" column="3">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</spacer>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_textheight">
<property name="text">
@@ -138,13 +143,6 @@ as &quot;Arial&quot;, a style such as &quot;sans&quot;, &quot;serif&quot; or &qu
</property>
</widget>
</item>
<item row="1" column="2">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</spacer>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_LineSpacing">
<property name="text">
@@ -695,6 +693,11 @@ used for linear dimensions.</string>
<extends>QComboBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefFontBox</class>
<extends>QFontComboBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefSpinBox</class>
<extends>QSpinBox</extends>

View File

@@ -367,6 +367,29 @@ def _param_from_PrefFileChooser(widget):
return path, entry, ""
def _param_from_PrefFontBox(widget):
if App.GuiUp:
from PySide import QtGui
font = QtGui.QFont()
font.setStyleHint(QtGui.QFont.StyleHint.SansSerif)
value = font.defaultFamily()
else:
value = ""
for elem in list(widget):
if "name" in elem.keys():
att_name = elem.attrib["name"]
if att_name == "prefEntry":
entry = elem.find("cstring").text
elif att_name == "prefPath":
path = elem.find("cstring").text
# We must set the parameter if it does not exist, else
# the Gui::PrefFontBox will show the wrong value.
param_grp = App.ParamGet("User parameter:BaseApp/Preferences/" + path)
if entry not in param_grp.GetStrings():
param_grp.SetString(entry, value)
return path, entry, value
def _get_param_dictionary():
# print("Creating preferences dictionary...")
@@ -595,6 +618,9 @@ def _get_param_dictionary():
elif att_class == "Gui::PrefFileChooser":
path, entry, value = _param_from_PrefFileChooser(widget)
typ = "string"
elif att_class == "Gui::PrefFontBox":
path, entry, value = _param_from_PrefFontBox(widget)
typ = "string"
if path is not None:
if path in param_dict: