Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的应用程序中有一个(QT)工具栏,由 QAction 对象填充,其中一个 QAction 具有关联的菜单。我想在触发操作时在 QActions 按钮下方弹出该菜单。
我努力了:
m_ui->action_NewDataType->menu()->show();
但这显示了屏幕左上角的菜单,而不是我想要的位置。如何在 QAction 按钮下方显示菜单,并与按钮的边缘很好地对齐?
问题解决了:
QWidget* w = m_ui->mainToolBar->widgetForAction(m_ui->action_NewDataType); m_ui->action_NewDataType->menu()->popup(w->mapToGlobal(QPoint(0, w->height())))