QTableWidget中设置右键点击事件:
tableWidget->setContextMenuPolicy(Qt::CustomContextMenu);
connect(tableWidget,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(rightMouseClicked()));
contextMenuPolicy:
This property holds how the widget shows a context menu.
这个属性用来设置widget如何显示一个context menu
enum:
Constant Value Description
Qt::NoContextMenu 0 the widget does not feature a context menu, context menu
handling is deferred to the widget's parent.
widget中没有出现context menu,context menu的处理将会顺延
到parent。
Qt::PreventContextMenu 4 the widget does not feature a context menu, and in
contrast to NoContextMenu, the handling is not deferred
to the widget's parent. This means that all right mouse
button events are guaranteed to be delivered to the
widget itself through QWidget::mousePressEvent(), and
QWidget::mouseReleaseEvent().
部件没有出现context menu。与NoContextMenu相比,处理不会顺延
到parent。意味着所有的鼠标右击事件都将交给QWidget::mousePressEvent(),
and QWidget::mouseReleaseEvent()处理
Qt::DefaultContextMenu 1 the widget's QWidget::contextMenuEvent() handler is
called.
(默认)ContextMenuEvent 请求处理相应
Qt::ActionsContextMenu 2 the widget displays its QWidget::actions() as context menu.
widget显示它的QWidget::actions()作为context menu
Qt::CustomContextMenu 3 the widget emits the QWidget::customContextMenuRequested() signal.
//widget发送QWidget::customContextMenuRequested()信号。
本文介绍在Qt中如何为QTableWidget设置右键点击事件以显示自定义上下文菜单的方法。通过设置contextMenuPolicy属性并连接customContextMenuRequested信号,可以实现对表格控件的右键菜单功能。
1060

被折叠的 条评论
为什么被折叠?



