
我把我的代码共享一下吧(Qt3实现)
void Entry::contextMenuEvent( QContextMenuEvent * e)
{
if(e->x()>40 && e->y()>163 && e->x()<603 && e->y()<387)//位置范围判断
{
QPopupMenu* contextMenu = new QPopupMenu( Entry::table1 );
Q_CHECK_PTR( contextMenu );
QLabel *caption = new QLabel( "<font color=darkblue><u><b>"
"Context Menu</b></u></font>", this );
caption->setAlignment( Qt::AlignCenter );
contextMenu->insertItem( caption );
//contextMenu->insertItem( tr("&Add"), this, SLOT(addRecord()), CTRL+Key_A );
contextMenu->insertItem( tr("&Delete..."), this, SLOT(delRecord()), CTRL+Key_D );
contextMenu->insertItem( tr("&Save"), this, SLOT(saveRecord()), CTRL+Key_S );
contextMenu->exec( QCursor::pos() );
delete contextMenu;
}
}