双击QTableView的未使用区域 [英] Catch double click in QTableView's unused area

查看:106
本文介绍了双击QTableView的未使用区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序从一个空表开始,我想实施不同的方法来添加项目.一种方法是双击表的未使用区域(或背景"),该区域未被任何单元格占用.双击单元格时,我想要默认的行为.

My application starts with an empty table, and I want to imlement different methods to add items. One should be by double-clicking the table's unused area (or "background") that is not occupied by any cells. When a cell is double-clicked, I want the default behavior.

我已经找到了通过在我的TestTable类中重新实现QAbstractScrollArea::mouseDoubleClickEvent()方法来实现此目的的方法:

I've found way to do this by re-implementing QAbstractScrollArea::mouseDoubleClickEvent() method in my TestTable class:

#include <QMouseEvent>
#include <QTableView>

class TestTable : public QTableView
{
  Q_OBJECT
  signals:
    void backgroundDoubleClickEvent(void);
  protected:
    void mouseDoubleClickEvent (QMouseEvent* e)
    {
      if (indexAt(e->pos()).isValid())
      {
          QTableView::mouseDoubleClickEvent(e);
      }
      else
      {
        e->accept();
        emit backgroundDoubleClickEvent();
      }

    }
};

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆