QMenu *pMenu = new QMenu(this);
? ? QAction *pTest1 = new QAction(QIcon("copy.ico"),"復(fù)制", this);
? ? QAction *pTest2 = new QAction("刪除", this);
? ? QAction *pTest3 = new QAction("標(biāo)記", this);
? ? QAction *pTest4 = new QAction("取消標(biāo)記", this);
? //把QAction對象添加到菜單上
? ? pMenu->addAction(pTest1);
? ? pMenu->addAction(pTest2);
? ? pMenu->addAction(pTest3);
? ? pMenu->addAction(pTest4);
? ? //添加分隔線
? ? //pMenu->addSeparator();
? ? //設(shè)置點擊后發(fā)送的數(shù)據(jù)
? // pTest1->setData(1);
? ? //連接鼠標(biāo)右鍵點擊信號
? ? connect(pTest1, &QAction::triggered, this, &sub::ClickCopy);
? ? connect(pTest2, &QAction::triggered, this, &sub::ClickDel);
? ? connect(pTest3, &QAction::triggered, this, &sub::Clicktink);
? ? connect(pTest4, &QAction::triggered, this, &sub::ClickDeltink);
? ? //在鼠標(biāo)右鍵點擊的地方顯示菜單
? ? pMenu->exec(cursor().pos());
? ? //釋放內(nèi)存,若此處不手動釋放博杖,則必須等到程序結(jié)束時才都能釋放
? ? QList list = pMenu->actions();
? ? foreach (QAction* pAction, list)
? ? ? ? delete pAction;
? ? delete pMenu;