Qt ContextMenu

来源:互联网 发布:nas网络存储器 编辑:程序博客网 时间:2024/05/21 21:40

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   DescriptionQt::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 menuQt::CustomContextMenu     3     the widget emits the QWidget::customContextMenuRequested() signal.                                //widget发送QWidget::customContextMenuRequested()信号。
0 0
原创粉丝点击