//mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QLabel>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
void init();
protected:
bool eventFilter(QObject *obj, QEvent *e);
private:
Ui::MainWindow *ui;
QLabel *label;
};
#endif // MAINWINDOW_H
//mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <QMouseEvent>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
init();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::init()
{
label = new QLabel(ui->tableWidget);
label->setText("ID");
label->move(1,5);
label->installEventFilter(this);
}
bool MainWindow::eventFilter(QObject *obj, QEvent *e)
{
if (obj == label)
{
if (e->type() == QEvent::MouseButtonPress)
ui->tableWidget->selectAll();
}
return false;
}