wxTreeCtrl context menu Topic is solved

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
Mike A
In need of some credit
In need of some credit
Posts: 3
Joined: Sun Jan 29, 2006 2:34 am

wxTreeCtrl context menu

Post by Mike A » Sun Jan 29, 2006 2:44 am

Hi- I am using a wxTreeCtrl and setup the context menu in the frame; like this:

EVT_TREE_ITEM_MENU( ID_TREE_SPEC, Frame::OnTreeSpecItemMenu )


then when I do this:

void Frame::OnTreeSpecItemMenu( wxTreeEvent& event )
{
wxMenu* menu = new wxMenu;
menu->Append(wxID_OPEN, wxT("Open"));
PopupMenu(menu, event.GetPoint());
delete menu;
}

It all works as I would expect- ie poping up the menu when I right click on a tree item- but the menu is getting placed about 1 inch too high, instead of right next to the item the user right clicked on. I can't seem to find anything that would cause this- does anyone have any ideas?

BTW- i'm using wxDev-C++ with wxWidgets 2.6.1
Thanks for any help.

Cursor
Earned some good credits
Earned some good credits
Posts: 120
Joined: Sun Aug 29, 2004 3:09 pm
Location: Grenoble, France
Contact:

Post by Cursor » Sun Jan 29, 2006 9:57 am

You can use the
bool PopupMenu(wxMenu* menu, const wxPoint& pos = wxDefaultPosition)
with the wxDefaultPosition at third param, it will automatically place the menu at mouse position.

And if you really want to show your menu at the right side of the item, you can use wxTreeCtrl::GetBoundingRect [1] to retrieve it position.

1 : http://www.wxwidgets.org/manuals/2.6.2/ ... etitemrect
What is little and green, witch go up and down ??
Yoda playing with the force.

Mike A
In need of some credit
In need of some credit
Posts: 3
Joined: Sun Jan 29, 2006 2:34 am

Post by Mike A » Sun Jan 29, 2006 3:43 pm

ahhh- that did the trick! Thank you so much for taking the time-


:D

Post Reply