Skip to content

Instantly share code, notes, and snippets.

@ShenTengTu
Created March 13, 2024 13:34
Show Gist options
  • Save ShenTengTu/7e35a5b92b299b057139aee37cd27b51 to your computer and use it in GitHub Desktop.
Save ShenTengTu/7e35a5b92b299b057139aee37cd27b51 to your computer and use it in GitHub Desktop.
[Python] Qt: Function with overloaded type hints, equivalent to "QItemEditorFactory.defaultFactory().createEditor"
@overload
def defaultEditorFactory(arg: Type[bool], parent: QWidget) -> QComboBox: ...
@overload
def defaultEditorFactory(arg: Type[float], parent: QWidget) -> QDoubleSpinBox: ...
@overload
def defaultEditorFactory(arg: Type[int], parent: QWidget) -> QSpinBox: ...
@overload
def defaultEditorFactory(arg: Type[QDate], parent: QWidget) -> QDateEdit: ...
@overload
def defaultEditorFactory(arg: Type[QDateTime], parent: QWidget) -> QDateTimeEdit: ...
@overload
def defaultEditorFactory(arg: Type[QPixmap], parent: QWidget) -> QLabel: ...
@overload
def defaultEditorFactory(arg: Type[str], parent: QWidget) -> QLineEdit: ...
@overload
def defaultEditorFactory(arg: Type[QTime], parent: QWidget) -> QTimeEdit: ...
@overload
def defaultEditorFactory(arg: type, parent: QWidget) -> QWidget: ...
def defaultEditorFactory(arg, parent):
from qtpy.QtCore import QMetaType
from qtpy.QtWidgets import QItemEditorFactory
return QItemEditorFactory.defaultFactory().createEditor(QMetaType(arg).id(), parent)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment