Application Development in Linux: using QT to create Skin
Source: Internet
Author: User
Article Title: Application Development in Linux: using QT to create Skin. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
The style change of the software interface can be completed through two mechanisms: one is to set Themes, which uses the Components of the interface library itself) the control capability of the switch display style; the other is to provide different series of images to switch the display interface, that is, the Skin mentioned here.
There are several important factors worth considering when preparing the skin:
1. Use a borderless window In XWindow, a borderless window is a window that is not subject to irregular boundaries managed by the window manager. Because it is not managed by the window manager, there is no Title Bar attached to the software window interface. In Qt, the simplest way to create a borderless window is to set the WFlags value of QWidget to WStyle_NoBorder. It is defined in qnamespace. h. The image mask must be used for the entire window. X Shape Extension is used to meet the requirements. Can be used directly in Qt,
2. Move the window Because the above windows are not managed by the window manager, special processing is required for moving the windows. The general method is to intercept the mouse button event of the root Widget and process the mouse clicking and moving events by yourself.
Void SkinDemo: mousePressEvent (QMouseEvent * e)
{
Last = e-> globalPos ();
Pos0 = e-> globalPos ()-e-> pos ();
}
Here, we get the absolute cursor position, that is, relative to the root window position, and also record the position in the upper left corner of the window. When the mouse moves, we get a new absolute position, the new position in the upper left corner of the window should be the difference between the original position and the move of the mouse.
3. Button Creation For the image button in the skin, set its parent class to QButton. This button consists of two images, one of which is Normal ), an image is the status (Activated) when the button is pressed ). It can also be set to four States: the Disabled state and the Hovered state when the mouse pointer enters ).
In the example (qt-skin-example.tar.gz), we redefine the event processing function for mouse-pressed and mouse-moved, and it contains all information about buttons and all information about the main workspace. The information of the main work area is its position and size, and the information of the main window is the mask of the background image and image it uses (used to create irregular window ports ), therefore, the size of the main window can be determined by the image size. The information of several buttons contains their positions. Their size is determined by the image size.
The following is one of the program running results:
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.