简体   繁体   中英

Change Expand/Collapse icon in wxDataViewCtrl

I want to replace the Expand/Collapse icon with my icons in wxDataViewCtrl.

在此处输入图片说明

I am not able to find a way to set my expand/collapse icons. Is there any API available for the same?

or

Do I need to modify the wxDataViewCtrl source directly? your prior experience can help me.

The main point of having wxDataViewCtrl in the first place is that it wraps the corresponding native control, so changing its look and feel is not supported.

This being said, if you're using its generic implementation, as is always the case under MSW, you can actually change it by defining a custom wxRendererNative -derived class and overriding its DrawTreeItemButton() method. But this would affect all the other controls drawing tree-like buttons, including, obviously, generic wxTreeCtrl itself but also wxPropGrid . Generally speaking I wouldn't recommend doing this.

I do not know whether it is right approach or wrong, Here I found a way to achieve my thing based on VZ.suggestion.

class MyRenderer : public wxDelegateRendererNative
{
public:
    MyRenderer() : wxDelegateRendererNative(wxRendererNative::GetDefault()) { }

    virtual void DrawTreeItemButton(wxWindow *win,
        wxDC& dc,
        const wxRect& rect,
        int flags = 0)
    {
        MyCustomCtrl* pWin = dynamic_cast<MyCustomCtrl*>(win->GetParent());
        if (pWin != nullptr)
        {
            // Draw my choice of expand/collapse button.
        }
        else
        {   // Do not affect other controls that are using this drawing.
            wxRendererNative::GetDefault().DrawTreeItemButton(win, dc, rect, flags);
        }
    }
};

This way I can override the

virtual void DrawItemSelectionRect(wxWindow *win,
        wxDC& dc,
        const wxRect& rect,
        int flags)

and many more native drawings.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM