![]() Positions above and to the left of the client area have negative coordinates, which is important if you track the mouse position outside the window. Mouse coordinates are given in pixels, not device-independent pixels (DIPs), and are measured relative to the client area of the window. The macros extract the right values, so if you use them, you will be safe. In the 64-bit case, this means the low- and high-order words of the lower 32 bits. The MSDN documentation mentions the "low-order word" and "high-order word" of lParam. The upper 32 bits of lParam are not used. On 64-bit Windows, lParam is 64-bit value. These macros are defined in the header file WindowsX.h. Use the GET_X_LPARAM and GET_Y_LPARAM macros to unpack the coordinates from lParam. The lowest 16 bits of lParam contain the x-coordinate, and the next 16 bits contain the y-coordinate. In all of these messages, the lParam parameter contains the x- and y-coordinates of the mouse pointer. For more information about client areas, see What Is a Window? Mouse Coordinates Recall that the client area is the portion of the window that excludes the frame. # print("my position is:",self.xx,self.If the user clicks a mouse button while the cursor is over the client area of a window, the window receives one of the following messages. # Mouse click event is used to process events after mouse click, including: # Mouse movement event, used to obtain accurate coordinates (as if the coordinates clicked by the mouse were inaccurate) # Start the timer and notify to refresh the data every 1 second # In this way, only the curve is re plot ted, and the performance is higher # The real-time display should obtain the PlotDataItem object and call its setData method, # Set the upper, lower, left and right label s All complete codes are as follows, which can be used directly after copying: # Capture mouse movement eventsįrom PySide2 import QtGui, QtWidgets, QtCore The above is all the ideas to solve my needs. # The parameter pos is a pixel coordinate, which needs to be converted into a scale coordinate # After capturing the click event, the actions to be done are completed in the mouseover function, mainly extracting the coordinates of the points The main codes of mouse movement are as follows: # Capture mouse movement events So in the whole program, I used two trigger events, one is mouse click and the other is mouse movement. After testing, the coordinates extracted by moving the mouse event are accurate. Normally, the return value of sigMouseClicked is an event, which contains the coordinates of the click time, but this coordinate is inaccurate, which is somewhat different from the actual position. # After capturing the click event, you need to do the action in mouse_ Completed in the clicked functionī) Get the coordinates corresponding to the graphic position when the mouse clicks. The main code is as follows: # Capture mouse click events In practice, I also divide this part into two steps: a) capture the mouse click signal. I haven't used pyqt before, so I don't know how to capture the mouse click signal, let alone extract the corresponding position coordinates. (self.updateData)ģ) Left click the drawing interface to add a new point. # Start the timer and notify to refresh the data every 100ms # Give the X and Y coordinates of points and draw a scatter diagramĢ) After the number of nodes or coordinates change, the position can be updated in real time. Self.scatter = .plot(pen=None, symbol='o') My requirements are mainly divided into the following parts: 1) Given the node coordinates, it can be displayed in the form of scatter diagram. I learned from the online code, combined with my own needs, and finally realized the functions I needed. After a search, I found that pyqt seemed to meet my needs, and I could find some relevant code. It feels that matplotlib completely depends on data-driven (that is, it can draw pictures by providing data), but it can not realize the two-way interaction between users and graphics (that is, users can generate new points by clicking with the mouse). However, it seems that it can not achieve the functions I need. In ordinary python drawing, my commonly used tool is matplotlib. In a recent project, the required function is to use the mouse to add nodes (the position where the mouse clicks is the node coordinates), and the point coordinates can be displayed visually and dynamically after being added. 1) Problem motivation and usage scenarios
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |