python pyqt5 QTableWidget 添加右键菜单

python pyqt5 QTableWidget 添加右键菜单,第1张

'''

【简介】

PyQT5的表格中支持右键菜单例子

'''

import sys

from PyQt5.QtWidgets import (QMenu, QPushButton, QWidget, QTableWidget, QHBoxLayout, QApplication, QTableWidgetItem,

QHeaderView)

from PyQt5.QtCore import QObject, Qt

class Table(QWidget):

if name == ' main ':

app = QApplication(sys.argv)

example = Table()

example.show()

sys.exit(app.exec_())

下面是我给treeWidget加的右键。。。楼主参考下,改下就可以了 复制代码 private slots: on_treeWidget_customContextMenuRequested(QPoint pos) 复制代码 ui->treeWidget->setContextMenuPolicy(Qt::CustomContextMenu)void Composer::on_treeWidget_customContextMenuRequested(QPoint pos) { currentItem = ui->treeWidget->itemAt( pos ) if( currentItem == 0) return QMenu *treeWidgeMenu = new QMenu(ui->treeWidget) treeWidgeMenu->addAction(ui->actionS_rename)treeWidgeMenu->addAction(ui->actionCollpase_Rooms)treeWidgeMenu->addAction(ui->actionUpdate_Driver)treeWidgeMenu->addSeparator()treeWidgeMenu->addAction(ui->actionS_delete)treeWidgeMenu->exec(QCursor::pos())}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11446056.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-16
下一篇 2023-05-16

发表评论

登录后才能评论

评论列表(0条)

保存