Qt 给按钮添加右键菜单

 

btn->setContextMenuPolicy(Qt::CustomContextMenu);
connect(btn, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showMenu(const QPoint&)));

void BookmarkLabel::showMenu(const QPoint& point)
{
  QPoint globalPos = this->mapToGlobal(point);
  m_pMenu->exec(QPoint(globalPos.x(), globalPos.y());
}

 

posted @ 2021-07-23 08:40  远方是什么样子  阅读(428)  评论(0编辑  收藏  举报