16, Qt event, custom control class

Mouse events (QMouseEvent): Press release, move

QEvent: enter, leave

Keyboard events (QKeyEvent): Press the keyboard

Timer events (QTimerEvent): open, stop

New Qt Widgets Application project, Base class selection QWidget, class name MyWidget

Add two label interface

Create mylabel class, temporarily inherited from QWidget (because there is no QLabel option), then h and cpp files into QLabel.

Interface label, the right mouse button - promoted , so QLabel class becomes class custom mylabel

The reason why the control class, in order to achieve some customized features. achieve the label mouse events, QEvent they enter and leave events

The timer event QWidget, the display on the label, label_2. Source download

Guess you like

Origin www.cnblogs.com/xixixing/p/12130968.html