I think I'm missing something because I do not see any way to easily cross-platform cursor in QT can . That is, I want to use a standard cursor editor, or just a normal cursor file type, and want to paste it into a resource file.
Let me provide some platform specific management handles (i.e. I can not load with a resource) or take a pixmap in a normal way. In the Pixmap method, I will have to wipe it in any way to store the hotspot.
I do not want animated cursors, just a plain color image (32x32).
What is the easiest way to deal with this?
I am currently working on an application where I want to do some good custom cursor The way I'm doing this:
-
Add an image to a QT resource file (
*. QRC ) - I with PNG with transparency Working is exported from SVG (ALWAYS your original art source for such things in SVG, like you need scaling) < Pre>
& lt; RCC & gt; & Lt; Qresource prefix = "/" & gt; & Lt; File alias = "default" & gt; Cursors / cursor_default.png & lt; / File & gt; & Lt; / Qresource & gt; & Lt; / RCC & gt;
This will allow you to ship your cursor with your application because the QT resource files are converted to C ++ sources, which are added to your binary
In your source code:
QPixmap cursor_pixmap = QPixmap (": cursor_default"); QCursor cursor_default = QCursor (cursor_picSmap, 0, 0); SetCursor (cursor_default);
Here are two important things to notice that are related to the constructor of both
QCursor - which you add it and the hotspot coordinates (both of which are set here < Code> 0 which represents the shape of your cursor, is in the upper left corner of that pixel). There are actually 2 constructors for
QCursor which are all useful here:
-
QCursor :: QCursor (Constant Cubitmap and Bitmap, Constant Cubitmap and Mask, Int Hotcode = -1, int hotY = -1) - This allows you to use a mask to manipulate the pixels of your cursor.
QCursor :: QCursor (const QPixmap and pixmap, int hotx = -1, at hot y = -1) - If you are working with a PNG or other supported image format May include which allows transparency you can find the mask because it is in my case.
The hotspot is a very important part of the cursor - it tells your application which part of your cursor is "trigger" which is the place that There is nothing compared to the rest which is just fancy and nothing functional.
While looking for resources on Qt optimization, I found (to see the image above), which I can completely recommend to every one Interested in this topic.
In the case of handling the hotspot I don do not think that something like this is necessary after all your resource files are compiled and added to the binary, when you allocate a hotspot for the cursor inside your code I would suspect that there is actually a format in any OS (multi-platform alone is one) which keeps both the cursor and its hotspot due to the fact that the application On the basis you want to change the hotspot which will be very difficult if you are bound by the cursor's bitmap? If you really want to go away with it (I can advise against it), then you can create your own custom file format that includes both. Since QT resource files are - for my knowledge - for managing images, you have to implement the whole IO mechanism to support your custom format.
Hope this helps, as the above solution is in the form of the Omoh cross-platform, as you can get from the QT framework. Note however that custom
QCursor will be available only in your application and wherever you set it to the cursor which is above the window frame, for example, OS-specific is considered to be due to the fact that The window frame itself is an OS-specific feature and if you want to change your behavior you will have to go deeper (and also outside the QT safe area).
Comments
Post a Comment