双击QTableView的未使用区域 [英] Catch double click in QTableView's unused area
本文介绍了双击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();
}
}
};
- 这行得通,但是有没有一种更优雅的方式来实现此功能而又无需将
QTableView
子类化? - 我不知道当前实施的任何限制.有明显的警告吗?
- This works, but is there a more elegant way of doing this without subclassing
QTableView
? - I'm not aware of any limitations of my current implementation. Are there obvious caveats?
推荐答案
If you don't want to subclass QTableView
, try installEventFilter
这篇关于双击QTableView的未使用区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文