擅长:python、mysql、java
<p>我用C++做的,但我觉得应该有用</p>
<p>在图形视图中:</p>
<pre><code>void MyGraphicsView::contextMenuEvent(QContextMenuEvent * event)
{
QGraphicsView::contextMenuEvent(event);
if(!event->isAccepted())
{
QMenu * menu = new QMenu;
menu->addAction("GraphicsView Action 1");
menu->addAction("GraphicsView Action 2");
menu->popup(event->globalPos());
}
}
</code></pre>
<p>在GraphicsItem中:</p>
^{pr2}$