Qt Getting Started Practical Tutorial (Table of Contents)
Precursor course
This article is an assignment for the article Qt mouse click event processing: displaying the mouse click position (complete example) (hereinafter referred to as the "precursor course").
In the precursor course, we fully demonstrated how to add member functions in QtCreator and use the refactoring tool to add function definitions.
You only need to imitate the precursor course to complete the assignment content of this article.
mouse movement event
Mouse movement events are the interface provided by the QWidget object:
void mouseMoveEvent(QMouseEvent *event);
We just need to reimplement this function.
We just need to imitate the approach in the "Precursor Course" in this function:
1. Add member functions to QtCreator and use the refactoring tool to add function definitions;
2 Use the move method to move the position of the QLabel control to the position where the mouse event is passed in;
3 Convert the mouse position into a string and set the content to be displayed to QLabel through QLabel's setText
4 Let QLabel adapt to the text size to display the text completely.
You only need to complete the above content to complete this assignment.
Complete effect
Start code download
Baidu cloud
Link: https://pan.baidu.com/s/1gjfPH1ucIGTqJHzb-_thmw
Extraction code: 1234
Gitee code cloud
let's start! Good luck!