/* The following are mouse movement events */
Void mainwindow: mousemoveevent (qmouseevent * m)
{// The function name and parameter here cannot be changed
Qcursor my (qpixmap ("E:/QT/Qt-creator-example/event/time.png "));
// Select an image for the mouse pointer,Note that the absolute path must be used, and "/" should be used instead of "/".
Qapplication: setoverridecursor (my );
// Change the mouse pointer to an image you have set
Int x = m-> pos (). X ();
Int y = m-> pos (). Y ();
// Obtain the coordinates of the current mouse position
UI-> Pushbutton-> settext (TR ("the coordinates of the mouse are (% 1, % 2), haha "). arg (X ). arg (y ));
// Display the coordinates of the mouse position on the button
UI-> Pushbutton-> move (m-> pos ());
// Move the button following the mouse
}
/* The following is the keyboard press event */
Void mainwindow: keypressevent (qkeyevent * K)
{
If (k-> key () = QT: key_a)// Judge whether the key A is pressed
{
UI-> label-> setpixmap (qpixmap ("E:/QT/Qt-creator-example/event/linux.jpg "));
UI-> label-> resize (100,100 );
// Change the label image and size
}
}
Note: These two functions are not newly created, but are redefined for existing functions. All function names and parameters cannot be changed. The first function overwrites the mouse movement event. You can change the mouse pointer and move the button following the mouse.
The second function implements the new function by pressing the key on the keyboard.