-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(qt): Add TreeView with keyEvent listener
- Loading branch information
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include "qtcomponents.h" | ||
|
||
QTreeViewWithKeyEvents::QTreeViewWithKeyEvents( QWidget *parent ) | ||
: QTreeView(parent) | ||
{ | ||
|
||
} | ||
|
||
void QTreeViewWithKeyEvents::onKeyPressed( void * handle, TreeViewKeyPressedEvent callback) | ||
{ | ||
mHandle = handle; | ||
mCallback = callback; | ||
} | ||
|
||
void QTreeViewWithKeyEvents::keyPressEvent( QKeyEvent *event ) | ||
{ | ||
if (mCallback != NULL && mHandle != NULL) | ||
{ | ||
mCallback(mHandle, event); | ||
} | ||
QTreeView::keyPressEvent(event); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef QTCOMPONENTS_H | ||
#define QTCOMPONENTS_H | ||
|
||
#include <QKeyEvent> | ||
#include <QTreeView> | ||
|
||
typedef void ( * TreeViewKeyPressedEvent)(void * handle, QKeyEvent * event); | ||
|
||
/** | ||
* A QTreeView that allow to define listener of keyEvent received | ||
*/ | ||
class QTreeViewWithKeyEvents : public QTreeView { | ||
Q_OBJECT | ||
|
||
public: | ||
explicit QTreeViewWithKeyEvents(QWidget *parent = NULL); | ||
|
||
public slots: | ||
void onKeyPressed(void * handleUsed, TreeViewKeyPressedEvent callback); | ||
|
||
protected: | ||
void keyPressEvent(QKeyEvent * event) override; | ||
|
||
private: | ||
TreeViewKeyPressedEvent mCallback; | ||
void * mHandle; | ||
}; | ||
|
||
#endif // QTCOMPONENTS_H |