Skip to content

MetaType

Qt Base Class: QMetaType

Signature: QMetaType(self) -> None QMetaType(self, arg__1: PySide6.QtCore.QMetaType.Type) -> None QMetaType(self, arg__1: type) -> None QMetaType(self, type: int) -> None

Base classes

Name Children Inherits
QMetaType
PySide6.QtCore
QMetaType(self) -> None

⋔ Inheritance diagram

graph TD
  1473299808192["core.MetaType"]
  1473243818384["QtCore.QMetaType"]
  1473291690208["Shiboken.Object"]
  140713234304496["builtins.object"]
  1473243818384 --> 1473299808192
  1473291690208 --> 1473243818384
  140713234304496 --> 1473291690208

🛈 DocStrings

Bases: QMetaType

Manages named types in the meta-object system.

Source code in prettyqt\core\metatype.py
class MetaType(QtCore.QMetaType):
    """Manages named types in the meta-object system."""

    def __bool__(self):
        return self.isValid()

    def __repr__(self):
        return get_repr(self, self.get_name())

    @classmethod
    def get_regular_types(cls):
        return [
            meta for i in range(TYPE_END_INDEX + 1) if (meta := MetaType(i)).isValid()
        ]

    @classmethod
    def get_enum_types(cls):
        return [
            meta
            for i in range(ENUM_START_INDEX, ENUM_END_INDEX + 1)
            if (meta := MetaType(i)).isValid()
        ]

    def get_name(self) -> str | None:
        return name.decode() if isinstance(name := self.name(), bytes) else name

    def get_type_name(self) -> str:
        return TYPE.inverse[QtCore.QMetaType.Type(self.id())]

    def is_enumeration(self) -> bool:
        return bool(self.flags() & QtCore.QMetaType.TypeFlag.IsEnumeration)

    # def get_meta_object(self) -> core.MetaObject:  # apparently doesnt exist in bindings
    #     return core.MetaObject(self.metaObject())

    # @classmethod  # and this one gives deprecated message
    # def get_meta_object_for_type(cls, typ: int) -> core.MetaObject:
    #     return core.MetaObject(cls.metaObjectForType(typ))

    def get_type(self) -> type:
        meta_type = QtCore.QMetaType.Type(self.id())
        match meta_type:
            case QtCore.QMetaType.Type.Bool:
                return bool
            case QtCore.QMetaType.Type.Int | QtCore.QMetaType.Type.UInt:
                return int
            case QtCore.QMetaType.Type.Double | QtCore.QMetaType.Type.Float:
                return float
            case QtCore.QMetaType.Type.QChar | QtCore.QMetaType.Type.QString:
                return str
            case QtCore.QMetaType.Type.QByteArray:
                return bytes
            case QtCore.QMetaType.Type.QVariantList | QtCore.QMetaType.Type.QStringList:
                return list
            case QtCore.QMetaType.Type.QVariantMap:
                return dict
            case QtCore.QMetaType.Type.QSize:
                return QtCore.QSize
            case QtCore.QMetaType.Type.QSizeF:
                return QtCore.QSizeF
            case QtCore.QMetaType.Type.QTime:
                return QtCore.QTime
            case QtCore.QMetaType.Type.QDate:
                return QtCore.QDate
            case QtCore.QMetaType.Type.QDateTime:
                return QtCore.QDateTime
            case QtCore.QMetaType.Type.QRect:
                return QtCore.QRect
            case QtCore.QMetaType.Type.QRectF:
                return QtCore.QRectF
            case QtCore.QMetaType.Type.QLine:
                return QtCore.QLine
            case QtCore.QMetaType.Type.QLineF:
                return QtCore.QLineF
            case QtCore.QMetaType.Type.QPoint:
                return QtCore.QPoint
            case QtCore.QMetaType.Type.QPointF:
                return QtCore.QPointF
            case QtCore.QMetaType.Type.QRegularExpression:
                return QtCore.QRegularExpression
            case QtCore.QMetaType.Type.QLocale:
                return QtCore.QLocale
            case QtCore.QMetaType.Type.QUrl:
                return QtCore.QUrl
            case _ if self.is_enumeration():
                return enum.Enum

        from prettyqt.qt import QtGui

        match meta_type:
            case QtCore.QMetaType.Type.QPolygon:
                return QtGui.QPolygon
            case QtCore.QMetaType.Type.QPolygonF:
                return QtGui.QPolygonF
            case QtCore.QMetaType.Type.QTextLength:
                return QtGui.QTextLength
            case QtCore.QMetaType.Type.QRegion:
                return QtGui.QRegion
            case QtCore.QMetaType.Type.QPalette:
                return QtGui.QPalette
            case QtCore.QMetaType.Type.QColor:
                return QtGui.QColor
            case QtCore.QMetaType.Type.QPen:
                return QtGui.QPen
            case QtCore.QMetaType.Type.QFont:
                return QtGui.QFont
            case QtCore.QMetaType.Type.QBrush:
                return QtGui.QBrush
            case QtCore.QMetaType.Type.QImage:
                return QtGui.QImage
            case QtCore.QMetaType.Type.QPixmap:
                return QtGui.QPixmap
            case QtCore.QMetaType.Type.QTransform:
                return QtGui.QTransform
            case QtCore.QMetaType.Type.QKeySequence:
                return QtGui.QKeySequence
            case QtCore.QMetaType.Type.QVector3D:
                return QtGui.QVector3D
            case QtCore.QMetaType.Type.QVector4D:
                return QtGui.QVector4D
            case QtCore.QMetaType.Type.QCursor:
                return QtGui.QCursor
            case QtCore.QMetaType.Type.QIcon:
                return QtGui.QIcon
            case QtCore.QMetaType.Type.QVariant:
                return object
            case QtCore.QMetaType.Type.QEasingCurve:
                return QtCore.QEasingCurve
            case QtCore.QMetaType.Type.QObjectStar:
                return QtCore.QObject

        from prettyqt.qt import QtWidgets

        match meta_type:
            case QtCore.QMetaType.Type.QSizePolicy:
                return QtWidgets.QSizePolicy
            case _:
                return object