• Qt 为QPushButton、QLabel


    mybutton.h

    #ifndef MYBUTTON_H
    #define MYBUTTON_H
    #include<QPushButton>
    #include<QEvent>

    class MyButton :public QPushButton
    {
    Q_OBJECT;
    public:
    MyButton(QWidget *parent = 0);
    ~MyButton();
    public:
    void enterEvent(QEvent *e); //鼠标进入事件
    void leaveEvent(QEvent *e);//鼠标离开事件
    };
    #endif // MYBUTTON_H
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    mylabel.h

    #ifndef MYLABEL_H
    #define MYLABEL_H

    #include<QLabel>
    #include<QEvent>

    class MyLabel :public QLabel
    {
    Q_OBJECT;
    public:
    MyLabel(QWidget *parent = 0);
    ~MyLabel();
    public:
    void enterEvent(QEvent *e);//鼠标进入事件
    void leaveEvent(QEvent *e);//鼠标离开事件
    };

    #endif // MYLABEL_H
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    mainwindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include "mybutton.h"
    #include "mylabel.h"
    #include <QMainWindow>

    namespace Ui {
    class MainWindow;
    }
    class MainWindow : public QMainWindow
    {
    Q_OBJECT
    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    MyButton *button1, *button2;
    MyLabel *myLabel;
    private:
    Ui::MainWindow *ui;
    };
    #endif // MAINWINDOW_H
    --------------------- 

  • 相关阅读:
    Python 爬虫一 简介
    linux 基础笔记本
    Celery 分布式任务队列快速入门
    Git & Github
    Python 设计模式
    Python 数据结构
    Python 基础算法
    js2wordcloud 词云包的使用
    lambda 3
    sql server 远程
  • 原文地址:https://www.cnblogs.com/hyhy904/p/11277942.html
Copyright © 2020-2023  润新知