'''
【简介】
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())}欢迎分享,转载请注明来源:内存溢出
评论列表(0条)