- Qt5 C++ GUI Programming Cookbook
- Lee Zhi Eng
- 371字
- 2021-07-02 12:17:54
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.
http://doc.qt.io/qt-5.12/stylesheet-reference.html.
- 電影中的精神病學(xué)
- Microsoft Dynamics 365 Business Central Cookbook
- 圖說災(zāi)難逃生自救叢書:海嘯
- Practical PowerShell Security and Compliance Center
- 媽媽寶寶口腔保健
- 你的第一本抑郁自救指南
- 全科常見急癥診療手冊
- 感染科專科醫(yī)師臨床思維
- 紫外線皮膚科實戰(zhàn)口袋書
- 復(fù)旦大學(xué)附屬華山醫(yī)院垂體疑難病多學(xué)科診治病例精選
- 骨科臨床X線檢查手冊
- Learning Geospatial Analysis with Python
- 非婦科脫落細(xì)胞學(xué)
- 同仁間接檢眼鏡臨床應(yīng)用手冊(同仁眼科手冊系列)
- 神經(jīng)系統(tǒng)疾病與精神障礙