Implemented the convenience method currentData of PyQt5 for PyQt4.

Tue, 11 Jul 2017 21:25:35 +0200

author
T.Rzepka <Tobias.Rzepka@gmail.com>
date
Tue, 11 Jul 2017 21:25:35 +0200
changeset 5802
abfb67a6f376
parent 5801
d3548bec88d1
child 5803
8faca1bed582

Implemented the convenience method currentData of PyQt5 for PyQt4.

Toolbox/PyQt4ImportHook.py file | annotate | diff | comparison | revisions
--- a/Toolbox/PyQt4ImportHook.py	Mon Jul 10 19:12:12 2017 +0200
+++ b/Toolbox/PyQt4ImportHook.py	Tue Jul 11 21:25:35 2017 +0200
@@ -44,6 +44,21 @@
             
             return None
         
+        @staticmethod
+        def QComboBox_currentData(other, role=None):
+            """
+            Public method to emulate the currentData method of Qt5.
+            
+            @param role role of which data should be retrived
+            @return stored data at current selection
+            """
+            import PyQt4.Qt
+            if role is None:
+                role = PyQt4.Qt.Qt.UserRole
+            
+            idx = other.currentIndex()
+            return other.itemData(idx, role)
+        
         def load_module(self, fullname):
             """
             Public method to load a module.
@@ -69,6 +84,8 @@
                     PyQt4.QtGui.QSortFilterProxyModel
                 module.QAbstractProxyModel = PyQt4.QtGui.QAbstractProxyModel
                 module.QStringListModel = PyQt4.QtGui.QStringListModel
+                
+                PyQt4.QtGui.QComboBox.currentData = self.QComboBox_currentData
             return module
 
     sys.meta_path.insert(0, PyQt4Importer())

eric ide

mercurial