Created
September 28, 2018 18:57
-
-
Save eyllanesc/6a326f94687f00cc2098b450740f0120 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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