def testSetPixmap(self): p1 = QPixmap(5, 5) p2 = QPixmap(10, 10) self.label.setPixmap(p1) self.assertIsNotNone(self.label.pixmap()) # PYSIDE-150: # When a new QPixmap is assigned to a QLabel, # the previous one needs to be cleared. # This means we should not keep a copy of the QPixmap # on Python-side. # Getting pointer to the QPixmap ret_p = self.label.pixmap() self.assertIsNot(p1, ret_p) # Save the address of the pointer ret_p_addr = shiboken.getCppPointer(ret_p) # Remove the QPixmap del ret_p # Set new QPixmap self.label.setPixmap(p2) # There should be no pointers remaining with the same # address that our QPixmap p1 because it was deleted # using `del ret_p` self.assertTrue(all(shiboken.getCppPointer(o) != ret_p_addr for o in shiboken.getAllValidWrappers()))
def pointer(widget): """ :param widget: ui name :return: """ from PySide2 import shiboken2 as shiboken return long(shiboken.getCppPointer(widget)[0])
def WidgetCreate(self, pWidgetParent): # # IN parameter pWidgetparent is the memory address of the parent Qt widget. # here we should PySide.shiboken.wrapInstance() function to convert it to PySide.QtWidget object. # and use it the as the parent for native Qt widgets created via Python. # Similiar approach is available in the sip python module for PyQt # # Only a single widget is allowed to be the *direct* child of the IN parent widget. # self.mNativeQtWidget = ReferencingSample.MainForm(shiboken2.wrapInstance(pWidgetParent, QtWidgets.QWidget)) # # return the memory address of the *single direct* child QWidget. # return shiboken2.getCppPointer(self.mNativeQtWidget)[0]
def WidgetCreate(self, pWidgetParent): # # IN parameter pWidgetparent is the memory address of the parent Qt widget. # here we should PySide.shiboken.wrapInstance() function to convert it to PySide.QtWidget object. # and use it the as the parent for native Qt widgets created via Python. # Similiar approach is available in the sip python module for PyQt # # Only a single widget is allowed to be the *direct* child of the IN parent widget. # self.mNativeQtWidget = ReferencingSample.MainForm( shiboken2.wrapInstance(pWidgetParent, QtWidgets.QWidget)) # # return the memory address of the *single direct* child QWidget. # return shiboken2.getCppPointer(self.mNativeQtWidget)[0]
def _qtAddress(o): import Qt if "PyQt" in Qt.__binding__: import sip return sip.unwrapinstance(o) else: if Qt.__binding__ == "PySide2": try: import PySide2.shiboken2 as shiboken except ImportError: import shiboken2 as shiboken else: try: import PySide.shiboken except ImportError: import shiboken return shiboken.getCppPointer(o)[0]
def _qtAddress( o ) : import Qt if "PyQt" in Qt.__binding__ : import sip return sip.unwrapinstance( o ) else : if Qt.__binding__ == "PySide2" : try : import PySide2.shiboken2 as shiboken except ImportError : import shiboken2 as shiboken else : try : import PySide.shiboken except ImportError : import shiboken return shiboken.getCppPointer( o )[0]
currentFile = str(__file__) global mainpath base = dirname(abspath(__file__)) mainpath = Path(base).parents[0] global barMenu barMenu = None for w in QtWidgets.qApp.allWidgets(): if w.inherits("QMenuBar"): ptr = shiboken2.getCppPointer(w) barMenu = shiboken2.wrapInstance(int(ptr[0]), QtWidgets.QWidget) global listeModName listeModName = [Path(f).stem for f in list(Path(mainpath).glob('*.py'))] global listeModPath listeModPath = [Path(f) for f in list(glob.glob('{}/*.py'.format(mainpath)))] class Reloader(QtWidgets.QDialog):
def unwrapinstance(obj): addr, = __shiboken2.getCppPointer(obj) return addr
def from_event(cls, event: QActionEvent): p, = shiboken2.getCppPointer(event) return cls.from_address(p)