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

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.
主站蜘蛛池模板: 黔西| 通州区| 固原市| 舞钢市| 新余市| 沙洋县| 盐亭县| 新津县| 延吉市| 玉环县| 繁峙县| 绥宁县| 建宁县| 乌拉特中旗| 冀州市| 桂阳县| 柳林县| 沙洋县| 曲靖市| 保德县| 柘城县| 宜宾县| 霍林郭勒市| 汉寿县| 高要市| 镇巴县| 容城县| 北安市| 霍山县| 尖扎县| 武强县| 柯坪县| 永靖县| 虹口区| 利辛县| 临西县| 三河市| 包头市| 金平| 微博| 边坝县|