Custom wxPGProperty without editor

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
shauser67
Earned a small fee
Earned a small fee
Posts: 11
Joined: Tue May 19, 2020 9:54 am

Custom wxPGProperty without editor

Post by shauser67 »

I have a number of properties in a wxPropertyGrid which I would like to group with a wxPGProperty acting as a header for its child properties. This header property should not display an editor when clicking on it.

I started with a wxStringProperty, but I found no way to disable the editor (e.g. by vetoing an event).

Simply calling wxStringProperty::Enable (false) prevents the editor from being shown, but now the label is greyed out (not what I want).

Is there a better solution for creating a wxPGProperty without editor?
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Custom wxPGProperty without editor

Post by ONEEYEMAN »

Hi,
Did you look at the sample to see whether you can get another propertype?

Thank you.
shauser67
Earned a small fee
Earned a small fee
Posts: 11
Joined: Tue May 19, 2020 9:54 am

Re: Custom wxPGProperty without editor

Post by shauser67 »

Hi ONEEYEMAN,

Thanks for your quick reply. I had a look a the propgrid sample again but couldn't find an example for the problem.

To clarify things, I would like to use another level of structuring properties:

Category (wxCategoryProperty)
- Subcategory
-- Property 1 (wxPGProperty)
-- Property 2 (wxPGProperty)

I tried to use wxCategoryProperty for the subcategories without success. Both categories and subcategories are shown on the same level without nesting.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Custom wxPGProperty without editor

Post by ONEEYEMAN »

Hi,
Then it is probably not supported.
You can make such modification and submit it as patch on trac or PR on github, or send an E-mail on wx-users ML to see if someone else already made such modification.

Also in any case you can create a ticket on the trac.wxwidgets.org about this, so that hopefully someone can make it.

Thank you.
shauser67
Earned a small fee
Earned a small fee
Posts: 11
Joined: Tue May 19, 2020 9:54 am

Re: Custom wxPGProperty without editor

Post by shauser67 »

Hi ONEEYEMAN,

Thanks for the advice! I had a closer look at the source of wxPropertyGrid and found a solution for my problem without changing wxWidgets itself. It is safe to create a custom wxPGEditor without any attached window:

Code: Select all

class EmptyEditor : public wxPGEditor
{
    public:
        EmptyEditor () {}

        ~EmptyEditor () override {}

        wxPGWindowList CreateControls (wxPropertyGrid *propGrid,
                                       wxPGProperty *property,
                                       const wxPoint &pos,
                                       const wxSize &sz) const override
        {
            return wxPGWindowList ();
        }

        void UpdateControl (wxPGProperty *property, wxWindow *ctrl) const override {}

        bool OnEvent (wxPropertyGrid *propGrid,
                      wxPGProperty *property,
                      wxWindow *ctrl,
                      wxEvent &event) const override
        {
            return false;
        }
};
This editor can be used in a custom property derived from wxPGProperty. It just has to display its label:

Code: Select all

class SubcategoryProperty : public wxPGProperty
{
    public:
        SubcategoryProperty () {}

        SubcategoryProperty (const wxString &label = wxPG_LABEL,
                             const wxString &name = wxPG_LABEL,
                             const wxString &value = wxEmptyString) :
        wxPGProperty (label, name)
        {
            m_value = value;
        }

        ~SubcategoryProperty () override {}

        const wxPGEditor *DoGetEditorClass () const override
        {
            if (!m_editor)
                m_editor = new EmptyEditor ();

            return m_editor;
        }

        wxString ValueToString (wxVariant &value, int argFlags) const override
        {
            return wxEmptyString;
        }

        bool StringToValue (wxVariant &variant, const wxString &text, int argFlags) const override
        {
            return false;
        }

    private:
        static EmptyEditor *m_editor;
};

EmptyEditor *SubcategoryProperty::m_editor = nullptr;
In my first attempt I used wxStringProperty together with wxPGProperty::Enable (false) which caused the label to be greyed out. The difference is not large, but the label is now shown with its correct color.
Post Reply