qtablewidget 文本改变_QT之——QTableWidget拖拽单元格并替换内容(进阶)

本文介绍了如何在QT中使用QTableWidget实现单元格的拖拽操作,通过重写eventFilter函数,监听鼠标事件,实现在特定列之间的内容交换。代码示例详细展示了初始化表格、鼠标事件处理以及交换数据的方法。
摘要由CSDN通过智能技术生成

所需待重写函数:

[virtual] bool QObject::eventFilter(QObject *watched, QEvent *event);

/*

* Filters events if this object has been installed as an event filter for the watched object.

* In your reimplementation of this function, if you want to filter the event out, i.e. stop it being handled further, return true; otherwise return false.

*/

以上来自官方辅助手册

说明:

通过事宜过滤器,即上述重写函数,可通过条件,筛选所需事宜

若是筛选乐成,若是此事宜后续不再使用,返回true,后续若是再次使用,返回false

若是筛选不乐成,则返回给父类,防止父类处于内部目的重新实现了 eventFilter()

代码示例:

MainWindow.h

#ifndef MAINWINDOW_H

#define MAINWINDOW_H

#include

#include

#define STANDFLDCOL0

#define LAYERFLDCOL1

namespace Ui {

class MainWindow;

}

class MainWindow : public QMainWindow

{

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值