Mouse move event & keyboard press event

Source: Internet
Author: User

 

/* 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.