Question

I am learning QT programming and I wonder if there is an easy way to dynamically set cursor colors to be exact inverse of the colors under the cursor. I assume that the exact shape of the cursor is unknown during the compilation time and cursors can be overloaded through resources.

Just give me some general directions, no need to write a fully working code for me :)

Thank you, Alex

Était-ce utile?

La solution

Might I suggest checking out this forum post on the Qt forums: How to read a color of a pixel on a Widget?

Here they explain that the best way to get the color at a certain pixel is to use the QImage::pixel(const QPoint & position) function. This function returns the color of the pixel at the given position. In your case you'll need to pass this function the mouse cursor's position.

To track the cursor's position use the QCursor::pos() function or if you need to track the position of the mouse at all moments you can override function in the QMouseEvent class such as pos() or globalPos() depending on your needs.

Now since you know the position of the cursor, the color of the cursor at a particular position, you simply need to create a new QCursor and set that cursor into the application using QApplication::changeOverrideCursor(QCursor) with your newly created cursor.

Some of these methods are costly in processing time, so I would advise you to think carefully about what your application is trying to achieve.

Hope that gives you a starting point. Good luck.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top