aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/PySide6/glue/qtgui.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2025-02-11 08:05:59 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2025-02-13 16:57:28 +0100
commit8f34aaf4df4648de59d74b1b6fe72302f63d89a4 (patch)
tree05589b4400a007cabf5a4ef8482f5143dae7dc47 /sources/pyside6/PySide6/glue/qtgui.cpp
parent75fbea983e04cff477716d9cb119b1638c22d719 (diff)
PySide6: Add QFont.Tag(str), QFont.Tag.fromString(), QFont.Tag.fromValue()
The constructor is a non-type template that checks the string length. Add a function for it. Pick-to: 6.8 Fixes: PYSIDE-3013 Change-Id: I35626c29edddf38c04c5b913a35b36c540c45d6a Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/pyside6/PySide6/glue/qtgui.cpp')
-rw-r--r--sources/pyside6/PySide6/glue/qtgui.cpp38
1 files changed, 38 insertions, 0 deletions
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;