QT 在一个窗口上右键加菜单怎么加?
------解决方案--------------------
分为三部:代码如下
a.通过QAction 类new 出一个QAction对象.如:m_actionImagePlayPause = new QAction(tr("play/pause" ), this); 第一个参数显示action的名字,第二个参数,为action所在页面.
b.通过addAction进行添加. addAction(m_actionImagePlayPause);
c.添加virtual void contextMenuEvent(QContextMenuEvent* event ); 事件.内容为
void PlayerView::contextMenuEvent(QContextMenuEvent* event)
{
QMenu *imageMenu = new QMenu(this );
imageMenu->addAction(m_actionImagePlayPause);
imageMenu->addSeparator();
imageMenu->addAction(m_actionImageForward);
imageMenu->addSeparator();
imageMenu->addAction(m_actionImageNext);
imageMenu->adjustSize();
imageMenu->exec( event ->globalPos());
}