-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrightclickabletablewidget.cpp
39 lines (34 loc) · 1 KB
/
rightclickabletablewidget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "rightclickabletablewidget.h"
#include <QMouseEvent>
#include <QDebug>
RightClickableTableWidget::RightClickableTableWidget(QWidget *parent)
: QTableWidget(parent)
{
cell_row = -1;
cell_col = -1;
}
void RightClickableTableWidget::mousePressEvent(QMouseEvent *event) {
if (event->button() != Qt::RightButton) {
QTableWidget::mousePressEvent(event);
return;
}
QTableWidgetItem* item = this->itemAt(event->pos());
if (item) {
cell_row = item->row();
cell_col = item->column();
}
}
void RightClickableTableWidget::mouseReleaseEvent(QMouseEvent *event) {
if (event->button() != Qt::RightButton) {
QTableWidget::mouseReleaseEvent(event);
return;
}
QTableWidgetItem* item = this->itemAt(event->pos());
if (item) {
if (item->row() == cell_row && item->column() == cell_col) {
emit cell_right_clicked(cell_row, cell_col, event->pos());
cell_row = -1;
cell_col = -1;
}
}
}