Skip to content

Commit

Permalink
updated _compatibility_members - added QFont.setWeight, Qt.MidButton
Browse files Browse the repository at this point in the history
updated _pyside6() - added QtCompat.QFont.setWeight functionality

updated _misplaced_members PySide2 to restore parity with current release.

updated _misplaced_members PySide6 to be consistent with PySide2.
  • Loading branch information
zoshua committed May 1, 2024
1 parent 66e379b commit 25e117d
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions Qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,16 @@ def createWidget(self, class_name, parent=None, name=""):
"""
_misplaced_members = {
"PySide6": {
"QtCore.QStringListModel": "QtCore.QStringListModel",
"QtGui.QStringListModel": "QtCore.QStringListModel",
"QtCore.Property": "QtCore.Property",
"QtCore.Signal": "QtCore.Signal",
"QtCore.Slot": "QtCore.Slot",
"QtCore.QAbstractProxyModel": "QtCore.QAbstractProxyModel",
"QtCore.QSortFilterProxyModel": "QtCore.QSortFilterProxyModel",
"QtCore.QItemSelection": "QtCore.QItemSelection",
"QtCore.QItemSelectionModel": "QtCore.QItemSelectionModel",
"QtCore.QItemSelectionRange": "QtCore.QItemSelectionRange",
"QtGui.QRegularExpressionValidator": "QtGui.QRegExpValidator",
"QtGui.QShortcut": "QtWidgets.QShortcut",
"QtGui.QAction": "QtWidgets.QAction",
Expand All @@ -955,6 +965,15 @@ def createWidget(self, class_name, parent=None, name=""):
},
"PySide2": {
"QtGui.QStringListModel": "QtCore.QStringListModel",
"QtGui.QStringListModel": "QtCore.QStringListModel",
"QtCore.Property": "QtCore.Property",
"QtCore.Signal": "QtCore.Signal",
"QtCore.Slot": "QtCore.Slot",
"QtCore.QAbstractProxyModel": "QtCore.QAbstractProxyModel",
"QtCore.QSortFilterProxyModel": "QtCore.QSortFilterProxyModel",
"QtCore.QItemSelection": "QtCore.QItemSelection",
"QtCore.QItemSelectionModel": "QtCore.QItemSelectionModel",
"QtCore.QItemSelectionRange": "QtCore.QItemSelectionRange",
"QtUiTools.QUiLoader": ["QtCompat.loadUi", _loadUi],
"shiboken2.wrapInstance": ["QtCompat.wrapInstance", _wrapinstance],
"shiboken2.getCppPointer": ["QtCompat.getCppPointer", _getcpppointer],
Expand Down Expand Up @@ -1096,6 +1115,12 @@ def createWidget(self, class_name, parent=None, name=""):
"getOpenFileNames": "QtWidgets.QFileDialog.getOpenFileNames",
"getSaveFileName": "QtWidgets.QFileDialog.getSaveFileName",
},
"QFont":{
"setWeight": "QtGui.QFont.setWeight",
},
"Qt": {
"MidButton": "QtCore.Qt.MiddleButton",
},
},
"PySide2": {
"QWidget": {
Expand Down Expand Up @@ -1414,9 +1439,38 @@ def _pyside6():
if hasattr(Qt, "_QtWidgets"):
Qt.QtCompat.setSectionResizeMode = \
Qt._QtWidgets.QHeaderView.setSectionResizeMode

def setWeight(func):
def wrapper(self, weight):
weight = {
100: Qt._QtGui.QFont.Thin,
200: Qt._QtGui.QFont.ExtraLight,
300: Qt._QtGui.QFont.Light,
400: Qt._QtGui.QFont.Normal,
500: Qt._QtGui.QFont.Medium,
600: Qt._QtGui.QFont.DemiBold,
700: Qt._QtGui.QFont.Bold,
800: Qt._QtGui.QFont.ExtraBold,
900: Qt._QtGui.QFont.Black,
}.get(weight, Qt._QtGui.QFont.Normal)

return func(self, weight)

wrapper.__doc__ = func.__doc__
wrapper.__name__ = func.__name__

return wrapper


decorators = {
"QFont": {
"setWeight": setWeight,
}
}

_reassign_misplaced_members("PySide6")
_build_compatibility_members("PySide6")
_build_compatibility_members("PySide6", decorators)


def _pyside2():
Expand Down

0 comments on commit 25e117d

Please sign in to comment.