pyqt5 实现右键自定义_pyqt5的QListWidget中设置右键菜单

本文介绍了如何在PyQt5中为QListWidget设置自定义右键菜单。通过设置ContextMenuPolicy为Qt.CustomContextMenu,连接customContextMenuRequested信号,并编写相应槽函数来创建和显示菜单项,如添加、删除和修改。
摘要由CSDN通过智能技术生成

QListWidget 是继承 QWidget 的, 所以 QListWidget 是有右键菜单的,

从文档上可以找到 QWidget 上有以下两个与右键菜单有关的函数:

Qt.ContextMenuPolicy

self)

self, Qt.ContextMenuPolicy

policy)

Qt.ContextMenuPolicy 是一个枚举类型:

Constant

Value

Description

Qt.NoContextMenu

0

the widget does not feature a context menu, context menu handling is deferred to the widget's 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 mousePressEvent(), and mouseReleaseEvent().

Qt.DefaultContextMenu

1

the widget's QWidget.contextMenuEvent() handler is called.

Qt.ActionsContextMenu

2

the widget displays

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值