设置QTableWidget的左上角CornerWidget的文字(二)

来源:互联网 发布:地瓜干块淘宝那家好 编辑:程序博客网 时间:2024/06/05 06:56
//mainwindow.h
#ifndef MAINWINDOW_H#define MAINWINDOW_H#include <QMainWindow>#include <QLabel>namespace Ui {class MainWindow;}class MainWindow : public QMainWindow{    Q_OBJECTpublic:    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;}
                                             
0 0
原创粉丝点击