Qt 为QPushButton、QLabel

mybutton.h

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

the MyButton class: public the QPushButton
{
the Q_OBJECT;
public:
the MyButton (the QWidget * parent = 0);
~ the MyButton ();
public:
void enterEvent (QEvent * E); // mouse events into the
void leaveEvent (QEvent * e); // mouse exit event
};
#endif // MYBUTTON_H
. 1
2
. 3
. 4
. 5
. 6
. 7
. 8
. 9
10
. 11
12 is
13 is
14
15
16
mylabel.h

#ifndef MYLABEL_H
#define MYLABEL_H

#include<QLabel>
#include<QEvent>

MyLabel class: public the QLabel
{
the Q_OBJECT;
public:
MyLabel (the QWidget * parent = 0);
~ MyLabel ();
public:
void enterEvent (QEvent * E); // mouse events into the
void leaveEvent (QEvent * e); // mouse leaving the event
};

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

Guess you like

Origin www.cnblogs.com/hyhy904/p/11277942.html