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
--------------------- 

猜你喜欢

转载自www.cnblogs.com/hyhy904/p/11277942.html