首页 > 其他分享 >QTableWidget 右键菜单

QTableWidget 右键菜单

时间:2022-11-10 11:15:02浏览次数:35  
标签:QTableWidget pActionDel QAction pos pContextMenu tableWidget ui 右键 菜单

头文件中:

    QMenu* m_pContextMenu;
    QAction* m_pActionDel;

构造函数中:

ui->tableWidget->setContextMenuPolicy(Qt::CustomContextMenu)
void CreateMenu()
{
    //创建菜单项
    m_pContextMenu = new QMenu(this);
    m_pActionDel = new QAction(this);
    m_pActionDel->setText(QString("删除"));
    m_pContextMenu->addAction(m_pActionDel);

    //菜单项
    connect(m_pContextMenu, SIGNAL(triggered(QAction*)), this, SLOT(SlotMenuClicked(QAction*)));
    bool b = connect(ui->tableWidget, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(tableContexMenuRequested(const QPoint&)));
    int i = 1;

}

槽函数:

void tableContexMenuRequested(const QPoint &pos)
{
    m_pSelectItem = ui->tableWidget->itemAt(pos);
    if(m_pSelectItem != nullptr){
        m_pContextMenu->exec(QCursor::pos());
    }
}

void SlotMenuClicked(QAction *act)
{
    if (act == m_pActionDel)
    {
        int nRow = m_pSelectItem->row();
        QTableWidgetItem* item = ui->tableWidget->item(nRow, 1);
 
        ui->tableWidget->removeRow(nRow);
    }
}

 

标签:QTableWidget,pActionDel,QAction,pos,pContextMenu,tableWidget,ui,右键,菜单
From: https://www.cnblogs.com/warmlight/p/16876394.html

相关文章

  • 使用SQL语句查询多级菜单中某级子集的所有父级
    使用SQL语句查询多级菜单中某级子集的所有父级SELECTt2.idFROM(SELECT@rAS_id,(SELECT@r:=PARENT_IDFROM......
  • vue3 递归菜单组件
    有一个需求,就是不知道菜单到底有多少级,需要按照层级一层层地遍历出来递归实现的三个流程:写函数写遍历条件设置终止条件实现逻辑父请求子组件,并且把列表值转给子组......
  • Pyhon|Aligo|右键上传阿里云盘
    资料项目:https://github.com/foyoux/aligo教程:https://www.cnblogs.com/foyou/p/15094643.html安装模块pipinstallaligo-ihttps://pypi.tuna.tsinghua.edu.cn/simp......
  • Part 4:Cocos2d-x开发实战-Cocos中的字符串、标签和菜单-关东升-专题视频课程
    Part4:Cocos2d-x开发实战-Cocos中的字符串、标签和菜单—17944人已学习课程介绍        介绍了Cocos2d-x文字和菜单相关知识,首选我们介绍了Cocos2d-x中的字符串,其......
  • 菜单绘制项的状态DrawItemEventArgs.state
    在学习之前先明白几个概念:一、NoAccelerator 没有键盘加速键,也就是俗称的“快捷键”;如,Ctrl+C,Ctrl+V等我们熟悉的快捷键就是键盘加速键;(可参照https://blog.csdn.net/u01......
  • WPF禁用TextBox右键菜单
    WPF禁用TextBox右键菜单如此做<TextBoxGrid.Row="1"HorizontalAlignment="Right"VerticalAlignment="Bottom"Padding="0055"FontSize="12"x:Name="txtBoxHe......
  • vue.js3:div上添加右键菜单([email protected])
    一,js代码:<template><div><divstyle="width:800px;margin:auto;display:flex;flex-direction:column;"><div>请选择上传图片:<inputtype="......
  • QTableWidget 遍历
    for(introw=0;row<ui->tableWidget->rowCount();row++){ for(intcol=0;col<ui->tableWidget->columnCount();col++) { QTableWidgetItem*item=ui->tableWidg......
  • 左侧菜单改造路由链接
    使用ElementUI实现左侧菜单改造路由链接Vue的项目中我们会经常用到Element,Iview..等轻量框架来实现页面布局。如果是不是彻底理解这些框架的各个功能和属性的话会带来很......
  • ElementUI的左侧菜单栏的小问题~~
    Vue后台管理的项目中使用了ElementUI的组件库。左侧菜单栏遇到了一些小问题,结果一步一步的解决了~~1,首先菜单栏的图标Icon不满足我们的需求,我们可以引入公司内部的样式ic......