wx工具栏:获取工具的位置和大小
wxToolBar: get position and size of a tool?
我有一个wxToolBar,里面有一个下拉项:
g_toolBar1->AddTool(TOOLBAR_CMD_CONTROL_DROPDOWN,_("Control elements"),MainWin::getBitmap(gearsXPM,"gears"),wxNullBitmap,wxITEM_DROPDOWN);
custParent->Connect(TOOLBAR_CMD_CONTROL_DROPDOWN,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(DrawCanvasSwitcher::OnToolbar),NULL,g_drawCanvas);
.... // add items to controlMenu here
g_toolBar1->SetDropdownMenu(TOOLBAR_CMD_CONTROL_DROPDOWN,controlMenu);
在某些情况下,我通过调用 PopupMenu(( 以编程方式打开下拉菜单。我的问题在这里:此功能在当前鼠标位置打开菜单,而不是像带有向下箭头的按钮那样在工具下方打开菜单。
那么:我怎样才能获得工具TOOLBAR_CMD_CONTROL_DROPDOWN的位置和大小,以便为下拉菜单计算合适的位置,以便将其交给 PopupMenu((?
谢谢!
您可以
尝试像我在下面所做的那样调用GetBestSize()
,也不要忘记在使用AddTool()
添加工具后调用Realize()
。
g_toolBar1->AddTool(TOOLBAR_CMD_CONTROL_DROPDOWN,_("Control elements"),MainWin::getBitmap(gearsXPM,"gears"),wxNullBitmap,wxITEM_DROPDOWN);
/* Added the next two lines. */
g_toolBar1->Realize();
wxSize toolBarPos = g_toolBar1->GetBestSize();
/* If you add more tools call Realize() after that again. */
custParent->Connect(TOOLBAR_CMD_CONTROL_DROPDOWN,wxEVT_COMMAND_TOOL_CLICKED,wxCommandEventHandler(DrawCanvasSwitcher::OnToolbar),NULL,g_drawCanvas);
.... // add items to controlMenu here
g_toolBar1->SetDropdownMenu(TOOLBAR_CMD_CONTROL_DROPDOWN,controlMenu);
然后,可以使用toolBarPos
调用PopupMenu()
方法,如下所示:
PopupMenu(controlMenu, toolBarPos.getWidth(), toolBarPos.getHeight());
相关文章:
- 将值指定给向量(2D)的向量中的某个位置
- 使用Unreal C++获取VR耳机的世界位置/方向
- 写入位置0x0000000C时发生访问冲突
- 如何将两个不同矢量的同一位置的两个元素组合在一起
- GL_SHADERSTORAGE_BUFFER位置是否与其他着色器位置冲突
- 如何使用cudaMallocManaged在指针位置初始化对象?(C++)
- 使用外部SDK工具链文件在VisualStudio上生成项目编译错误
- 在clang++预处理器中确定gcc工具链版本
- 无法获取webot::PositionSensor对象中位置传感器的值
- 非常量变量只读位置的赋值
- Visual Studio(或任何其他工具)能否将地址解释为调用堆栈(boost上下文)的开头
- 如何定义更改car类中car位置的方法
- 使用迭代器时如何访问对象在向量中的位置?
- 更改.cpp程序的输入文件中数据的位置会意外更改输出
- 求最大元素位置的分治算法
- wx工具栏:获取工具的位置和大小
- 查找Visual C++工具包括Visual Studio 2017的文件夹位置
- 在VS C++ 6.0中,哪些调试工具适合查找内存泄漏的位置
- 我如何告诉 xcode 用于在特定位置查找文件的工具链
- MFC:如何在旧版 MFC 版本 6 中保存工具栏的位置