Code Monkey home page Code Monkey logo

Comments (3)

kadir014 avatar kadir014 commented on May 24, 2024

If you meant ToggleSwitch it has a toggled signal, you can use it like this:

from pyqt5Custom import ToggleSwitch

...

tg = ToggleSwitch()

# this slot is connected to 'toggled' signal
def slot():
    if tg.isToggled():
        print("the toggle switch is on!")
        
    else:
        print("the toggle switch is off!")
        
tg.toggled.connect(slot)

from pyqt5-custom-widgets.

vladtimug avatar vladtimug commented on May 24, 2024

That works thank you. However isn't it a bit odd that the slot function can only be defined before it can actually be used? Otherwise the mechanism will crash. One other thing would be, how would you use this with classes? Giving that you have a initUI method of a class which handles all graphical elements on the window how could one use the slot mechanism outside of the initUI method sfn the custom widgets inside of that initUI method? From my trials I could not get it to work. :)

from pyqt5-custom-widgets.

kadir014 avatar kadir014 commented on May 24, 2024
However isn't it a bit odd that the slot function can only be defined before it can actually be used?
It actually depends on how you use signals & slots, of course you can't give the `slot` function to the signal before defining it. You can't use any object without defining them, otherwise you will get `'object' is not defined` error. However if you got any other error it is best to share the source code and the error traceback.


how could one use the slot mechanism outside of the initUI method
Unfortunately I couldn't understand what you meant here, but signal & slot system is not a new thing in my library. You can check out these links for further information on using signals and slots in PyQt5.

EDIT: Formatting

from pyqt5-custom-widgets.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.