Skip to content

Instantly share code, notes, and snippets.

@eyllanesc
Created September 28, 2018 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eyllanesc/6a326f94687f00cc2098b450740f0120 to your computer and use it in GitHub Desktop.
Save eyllanesc/6a326f94687f00cc2098b450740f0120 to your computer and use it in GitHub Desktop.
#include <QApplication>
#include <QTableView>
#include <QDebug>
#include <QStandardItemModel>
class MyEventReceiver: public QObject{
public:
using QObject::QObject;
public slots:
void onClick(const QModelIndex & index){
qDebug()<<__PRETTY_FUNCTION__ << index;
}
void onDoubleClick(const QModelIndex & index){
qDebug()<<__PRETTY_FUNCTION__ << index;
}
};
class FooTableView: public QTableView
{
public:
FooTableView(QWidget *parent=nullptr):
QTableView(parent),
receiver(new MyEventReceiver(this))
{
connect(this, &QTableView::clicked, receiver, &MyEventReceiver::onClick);
connect(this, &QTableView::doubleClicked, receiver, &MyEventReceiver::onDoubleClick);
}
private:
MyEventReceiver *receiver;
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
FooTableView w;
QStandardItemModel model(4, 4);
w.setModel(&model);
w.show();
return a.exec();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment