官术网_书友最值得收藏!

How it works...

Qt provides users the freedom of adding their own custom properties to any type of widget. Custom properties are very useful if you want to change a particular widget when a special condition is met, where Qt doesn't provide such a context by default. This allows the user to extend the usability of Qt and makes it a flexible tool for customized solutions. For example, if we have a row of buttons on our main window and we need one of them to change its color depending on which page the Tab Widget is currently showing, there is no way the buttons would know when they should change their color, because Qt itself has no built-in context for this type of situation. To solve this issue, Qt gives us a method to add our own properties to the widgets, which uses a generic function called QObject::setProperty(). To read the custom property, we can use another function called QObject::property().

Next, we will talk about sub-controls in Qt Style Sheets. Often, a widget is not just a single object, but a combination of more than one object or control, used to form a more complex widget. These objects are called sub-controls.

For example, a spin box widget contains an input field, a down button, an up button, an up arrow, and a down arrow, which is quite complicated compared to some other widgets. In this case, Qt grants us more flexibility by allowing us to change every sub-control using a style sheet if we wanted to. We can do so by specifying the name of the sub-control behind the widget's class name, separated by a double colon. For instance, if I want to change the image of the down button to a spin box, I can write my style sheet as follows:

QSpinBox::down-button {
image: url(:/images/spindown.png);
subcontrol-origin: padding;
subcontrol-position: right bottom;
}

That will only apply the image to the down button of my spin box, and not to any other parts of the widget. By combining custom properties, pseudo-states, and sub-controls, Qt provides us with a very flexible method to customize our user interface.

Visit the following link to learn more about pseudo-states and sub-controls in Qt:
http://doc.qt.io/qt-5.12/stylesheet-reference.html.
主站蜘蛛池模板: 巨鹿县| 攀枝花市| 饶河县| 韶关市| 西林县| 石屏县| 辽源市| 合水县| 乌恰县| 青神县| 信丰县| 尤溪县| 商南县| 丰都县| 调兵山市| 泽普县| 辉县市| 霍城县| 奉新县| 昭平县| 盐亭县| 诸暨市| 中山市| 石林| 涟水县| 武穴市| 宁陕县| 于田县| 介休市| 富裕县| 昌邑市| 高州市| 奇台县| 宜州市| 卢湾区| 金乡县| 杨浦区| 邻水| 定陶县| 康平县| 甘德县|