signal emit in preferences pages
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
- ebrahim raeyat
- Posts: 621
- Joined: Sun Sep 09, 2018 7:00 pm
- Location: Iran
- Contact:
signal emit in preferences pages
Is there a way to emit signal when we change a widget on preferences pages? for example when we uncheck a checkbox, we able to disable some widget? I mean before press apply. Thanks.
Re: signal emit in preferences pages
A checkbox natively emit signals when changes, such as 'stateChanged', 'clicked' or 'toggled'.
- ebrahim raeyat
- Posts: 621
- Joined: Sun Sep 09, 2018 7:00 pm
- Location: Iran
- Contact:
Re: signal emit in preferences pages
I know, but how can I use it with preferences dialog? I did not find any resource. I can do it with regular widget.
Re: signal emit in preferences pages
Maybe you should try to tell what you're functionnally trying to achieve, not technically. A checkbox is a checkbox, being it a single widget or enclosed in the preferences dialog.ebrahim raeyat wrote: ↑Sun Jul 31, 2022 4:51 pm I know, but how can I use it with preferences dialog? I did not find any resource. I can do it with regular widget.
Re: signal emit in preferences pages
"I did not find any resource."
you just have to go on a treasure hunt for the actual checkbox widget, starting from the mainwindow...
there are some examples on the forum of how to get hold of dialogue widgets, that's will take you quite far in narrowing things down.
you just have to go on a treasure hunt for the actual checkbox widget, starting from the mainwindow...
there are some examples on the forum of how to get hold of dialogue widgets, that's will take you quite far in narrowing things down.
- ebrahim raeyat
- Posts: 621
- Joined: Sun Sep 09, 2018 7:00 pm
- Location: Iran
- Contact:
Re: signal emit in preferences pages
For example I have a checkbox in my widget. when I create my own widget, I set signal & slot in the __init__ of my class:
Code: Select all
self.form.checkbox.clicked.connect(self.checkbox_clicked)
for example an observer like this. but this works when user click apply or ok in preferences page, I want signal when user click on checkbox:
https://forum.freecadweb.org/viewtopic. ... 14#p565614
Re: signal emit in preferences pages
This is Python. Are you also talking about using Python?ebrahim raeyat wrote: ↑Mon Aug 01, 2022 1:03 am for example an observer like this. but this works when user click apply or ok in preferences page, I want signal when user click on checkbox:
https://forum.freecadweb.org/viewtopic. ... 14#p565614
- ebrahim raeyat
- Posts: 621
- Joined: Sun Sep 09, 2018 7:00 pm
- Location: Iran
- Contact:
Re: signal emit in preferences pages
Yes. suppose you have two combobox, one for country and one for city. I want to able to when user change the country, I fill the city combobox with respect to country, then user select the city. How can I do it with python in preferences dialog? Thanks.
Re: signal emit in preferences pages
hm, the only difference with you making a widget and attaching a signal to it, and the pref widget is that you have the reference to your own widget...
so, treasure hunting for the correct widget (which is somewhere under mainwindow) is a way forward (the only?)
pref d is modal, so if the dialogue is up it has to be done through a thread, cannot remember if the widgets are persistent or not (if not then the widgets are simply not there if the dialogue is not up...)
this is hooking into the pref d and simulates clicking, so you can easily start from there and find your widget - and it is a treasure hunt..., printing widgets is your friend when drilling down the w hierarchy
https://forum.freecadweb.org/viewtopic. ... 12#p480412
so, treasure hunting for the correct widget (which is somewhere under mainwindow) is a way forward (the only?)
pref d is modal, so if the dialogue is up it has to be done through a thread, cannot remember if the widgets are persistent or not (if not then the widgets are simply not there if the dialogue is not up...)
this is hooking into the pref d and simulates clicking, so you can easily start from there and find your widget - and it is a treasure hunt..., printing widgets is your friend when drilling down the w hierarchy
https://forum.freecadweb.org/viewtopic. ... 12#p480412
Re: signal emit in preferences pages
Here are the basics. Obviously "self.form" can be initialized from a UI file.ebrahim raeyat wrote: ↑Mon Aug 01, 2022 7:12 am Yes. suppose you have two combobox, one for country and one for city. I want to able to when user change the country, I fill the city combobox with respect to country, then user select the city. How can I do it with python in preferences dialog? Thanks.
This snippet will add a page (called "TestPage") in FC preferences with 2 linked comboboxes.
Code: Select all
import FreeCADGui
from PySide2 import QtWidgets
class TestPrefPage:
def __init__(self, parent=None):
self.form = QtWidgets.QWidget(parent)
lay = QtWidgets.QVBoxLayout()
self.source = QtWidgets.QComboBox(self.form)
self.target = QtWidgets.QComboBox(self.form)
self.source.currentIndexChanged.connect(self.sourceChanged)
self.source.addItems(["Letters", "Numbers"])
lay.addWidget(self.source)
lay.addWidget(self.target)
self.form.setLayout(lay)
def sourceChanged(self, index):
strList = []
self.target.clear()
if index == 0:
strList = ["A", "B", "C"]
elif index == 1:
strList = ["1", "2", "3"]
self.target.addItems(strList)
def saveSettings(self):
pass
def loadSettings(self):
pass
FreeCADGui.addPreferencePage(TestPrefPage, "TestPage")