QT,鼠标在指定部件上右键弹出菜单

关键是:m_chartView->underMouse(),只有在图表上右键才会弹出菜单

void Curves::contextMenuEvent(QContextMenuEvent* e) {

	if (m_chartView->underMouse())     //只有鼠标在图表上右键才弹出设置
	{
		QMenu *viewMenu = menuBar()->addMenu(tr(""));
		styleAct = new QAction(tr("&Style ..."), viewMenu);         //全局的背景设置
		connect(styleAct, &QAction::triggered, this, &Curves::setStyle);
		viewMenu->addAction(styleAct);
		viewMenu->exec(e->globalPos());
		delete viewMenu;
		viewMenu = NULL;
	}
}

你可能感兴趣的:(qt)