-
Notifications
You must be signed in to change notification settings - Fork 56
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
Event for custom toggle state change? #1
Comments
If you meant 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) |
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. :) |
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 methodUnfortunately 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 |
I am trying to figure out how to perform a certain action only when a slider is turned on. I looked at the class definition but I was not able to figure out how to listen for events on that object. Could you offer some input on this?
The text was updated successfully, but these errors were encountered: