Modifying an existing dialog?

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
hokieengr
Posts: 62
Joined: Sat Dec 31, 2016 5:09 pm

Modifying an existing dialog?

Post by hokieengr »

I'm sure this has been covered elsewhere but I can't seem to find anything recent so I'll ask.

Is there a preferred method or modifying an existing dialog? Are we expected to use Qt Designer or can I just hand edit the text files for simple things? If we are only to use Designer, should we be using Qt 4 or 5?

Thank you!
User avatar
wandererfan
Veteran
Posts: 6326
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Modifying an existing dialog?

Post by wandererfan »

hokieengr wrote: Sat Jun 30, 2018 7:11 pm Is there a preferred method or modifying an existing dialog? Are we expected to use Qt Designer or can I just hand edit the text files for simple things? If we are only to use Designer, should we be using Qt 4 or 5?
I use Designer for Qt4. The Qt5 migration isn't quite ready as far as I know.
hokieengr
Posts: 62
Joined: Sat Dec 31, 2016 5:09 pm

Re: Modifying an existing dialog?

Post by hokieengr »

I asked this in a different thread because that's where the conversation meandered to but it's probably more appropriate to ask it here.

I've added a Pref checkbox to an existing dialog using Qt 4 Designer after I built and installed the widget library. After rebuilding my option is there and clickable, no issues.

However, I thought by using a PrefCheckbox widget that saving and restoring the state of the preference would be handled automatically but that does not seem to be the case. So that's my question: what's the proper procedure for saving, restoring, and accessing the current state of a preference?
User avatar
wandererfan
Veteran
Posts: 6326
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Modifying an existing dialog?

Post by wandererfan »

hokieengr wrote: Mon Jul 02, 2018 12:17 pm However, I thought by using a PrefCheckbox widget that saving and restoring the state of the preference would be handled automatically but that does not seem to be the case. So that's my question: what's the proper procedure for saving, restoring, and accessing the current state of a preference?
As far as updating, the magic is in the red box.
prefAutoManage.png
prefAutoManage.png (244.94 KiB) Viewed 865 times
Access in C++

Code: Select all

    Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
        .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/General");
    m_sectionEdges = hGrp->GetBool("ShowSectionEdges", 0l);
    m_handleFaces = hGrp->GetBool("HandleFaces", 1l);
Sorry, don't have a Python example handy.
hokieengr
Posts: 62
Joined: Sat Dec 31, 2016 5:09 pm

Re: Modifying an existing dialog?

Post by hokieengr »

That's kind of what I figured and what I believe I did. I'll confirm when I get home. On your machine, if you add a new Gui::PrefCheckBox, fill out the magic red box, save, go into your build directory and fire off make (and make install I suppose depending on how you do it), does the resulting checkbox work? If you click it, click OK, and reopen the dialog--does the state automatically get saved? Is there another step or script I have to run to let the magic know about my new little box?

Thanks a ton for the C++ example. That will help a lot. No need for Python right now since I'm working in C++.
User avatar
wandererfan
Veteran
Posts: 6326
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Modifying an existing dialog?

Post by wandererfan »

hokieengr wrote: Mon Jul 02, 2018 2:17 pm That's kind of what I figured and what I believe I did. I'll confirm when I get home. On your machine, if you add a new Gui::PrefCheckBox, fill out the magic red box, save, go into your build directory and fire off make (and make install I suppose depending on how you do it), does the resulting checkbox work? If you click it, click OK, and reopen the dialog--does the state automatically get saved? Is there another step or script I have to run to let the magic know about my new little box?
A couple of things I can think of off hand:

Code: Select all

void DlgPrefsTechDrawImp::saveSettings()
{
    cb_HidLine->onSave();
    cb_Angle->onSave();
    cb_Faces->onSave();          //<<<<<<<
    cb_SectionEdges->onSave();
    cb_PageUpdate->onSave();

    pcb_Normal->onSave();
    ...
    ...
    void DlgPrefsTechDrawImp::loadSettings()
{
    cb_HidLine->onRestore();
    cb_Angle->onRestore();
    cb_Faces->onRestore();     //<<<<<<<
    cb_SectionEdges->onRestore();
    cb_PageUpdate->onRestore();

    pcb_Normal->onRestore();
and IIRC you need to press Apply first and then OK (??I always do it this way. Don't know that it is strictly necessary).
prefApply.png
prefApply.png (117.38 KiB) Viewed 856 times
hokieengr
Posts: 62
Joined: Sat Dec 31, 2016 5:09 pm

Re: Modifying an existing dialog?

Post by hokieengr »

Of course I swear I did all that before posting but it worked this time....
Post Reply