aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/PySide6
diff options
context:
space:
mode:
Diffstat (limited to 'sources/pyside6/PySide6')
-rw-r--r--sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml19
-rw-r--r--sources/pyside6/PySide6/glue/qtgui.cpp38
2 files changed, 56 insertions, 1 deletions
diff --git a/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml b/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml
index 5caba0e12..1344c627c 100644
--- a/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml
+++ b/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml
@@ -632,7 +632,24 @@
<extra-includes>
<include file-name="QStringList" location="global"/>
</extra-includes>
- <value-type name="Tag" since="6.7"/>
+ <value-type name="Tag" since="6.7">
+ <inject-code class="native" position="beginning"
+ file="../glue/qtgui.cpp" snippet="qfont-tag-from-str-helper"/>
+ <add-function signature="Tag(QString@name@)">
+ <inject-code class="target" position="beginning"
+ file="../glue/qtgui.cpp" snippet="qfont-tag-init-str"/>
+ </add-function>
+ <add-function signature="fromString(QString@name@)"
+ static="true" return-type="QFont::Tag">
+ <inject-code class="target" position="beginning"
+ file="../glue/qtgui.cpp" snippet="qfont-tag-fromString"/>
+ </add-function>
+ <add-function signature="fromValue(int@value@)"
+ static="true" return-type="QFont::Tag">
+ <inject-code class="target" position="beginning"
+ file="../glue/qtgui.cpp" snippet="qfont-tag-fromValue"/>
+ </add-function>
+ </value-type>
<!-- PYSIDE-1685: QFont(QString) should be checked first, else it will be interpreted as sequence -->
<modify-function signature="QFont(const QString&amp;,int,int, bool)" overload-number="0"/>
<modify-function signature="QFont(const QStringList &amp;,int,int, bool)" overload-number="1"/>
diff --git a/sources/pyside6/PySide6/glue/qtgui.cpp b/sources/pyside6/PySide6/glue/qtgui.cpp
index aae660af7..f44ec6738 100644
--- a/sources/pyside6/PySide6/glue/qtgui.cpp
+++ b/sources/pyside6/PySide6/glue/qtgui.cpp
@@ -502,6 +502,44 @@ else
PyErr_SetString(PyExc_TypeError, "QVariant must be holding a QColor");
// @snippet qcolor
+// @snippet qfont-tag-from-str-helper
+using FontTagOptional = std::optional<QFont::Tag>;
+static std::optional<QFont::Tag> qFontTagFromString(PyObject *unicode)
+{
+ FontTagOptional result;
+ if (PyUnicode_GetLength(unicode) == 4)
+ result = QFont::Tag::fromString(PySide::pyUnicodeToQString(unicode));
+ if (!result.has_value())
+ PyErr_SetString(PyExc_TypeError,
+ "QFont::Tag(): The tag name must be exactly 4 characters long.");
+ return result;
+}
+// @snippet qfont-tag-from-str-helper
+
+// @snippet qfont-tag-init-str
+const FontTagOptional tagO = qFontTagFromString(%PYARG_1);
+if (tagO.has_value())
+ %0 = new QFont::Tag(tagO.value());
+// @snippet qfont-tag-init-str
+
+// @snippet qfont-tag-fromString
+const FontTagOptional tagO = qFontTagFromString(%PYARG_1);
+if (tagO.has_value()) {
+ const auto &tag = tagO.value();
+ %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](tag);
+}
+// @snippet qfont-tag-fromString
+
+// @snippet qfont-tag-fromValue
+const FontTagOptional tagO = QFont::Tag::fromValue(PyLong_AsUnsignedLong(%PYARG_1));
+if (tagO.has_value()) {
+ const auto &tag = tagO.value();
+ %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](tag);
+} else {
+ PyErr_SetString(PyExc_TypeError, "QFont::Tag::fromValue(): Invalid value passed.");
+}
+// @snippet qfont-tag-fromValue
+
// @snippet qfontmetricsf-boundingrect
int *array = nullptr;
bool errorOccurred = false;