Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compatibility with pyside2 #1

Open
laser101 opened this issue Jul 26, 2018 · 2 comments
Open

Add compatibility with pyside2 #1

laser101 opened this issue Jul 26, 2018 · 2 comments

Comments

@laser101
Copy link

Hi,

I've successfully used the PyQt5Singleton class in my PyQt5 projects, but am currently looking at a project that uses qtpy to abstract away PyQ5 and pyside2, allowing either frameworks to be used.

Unfortunately I haven't been able to get PyQt5Singleton to work with pyside2 (either directly, or via qtpy). Do you have any suggestions for how this might be approached.

Thanks,

Russ

@fmassucci
Copy link

Did you manage to implement it with PySide?

@nrbnlulu
Copy link

nrbnlulu commented Feb 14, 2023

here is a PySide6 implementation

class QSingleton(type(QObject)):
    def __init__(cls, name, bases, dict):
        super().__init__(name, bases, dict)
        cls.instance=None

    def __call__(cls,*args,**kw):
        if cls.instance is None:
            cls.instance=super().__call__(*args, **kw)
        return cls.instance
# Usage
class Foo(QObject, metaclass=QSingleton):
    ...

@fmassucci

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants