文章目录
QGroupBox控件样式
- 子控件
- 常用属性
QSS示例
-
新建一个 QMainWIndow 窗口,在其中放入四个 QGroupBox 控件。
cssQGroupBox { background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #E0E0E0, stop: 1 #FFFFFF); border: 2px solid gray; border-radius: 5px; font: 20px; }
-
分别设置这四个 QGroupBox 可观察其区别。
cssQGroupBox { background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #E0E0E0, stop: 1 #FFFFFF); border: 2px solid gray; border-radius: 5px; font: 20px; } #groupBox{ margin-top: 3ex; /*表示margin距border有3个距离*/ } #groupBox::title{ subcontrol-origin: margin; /* 和margin的起点对齐 */ subcontrol-position: top center; background-color: red; } #groupBox_2{ padding-top: 5ex; /*与groupBox_3进行对比,可看出区别*/ } #groupBox_2::title{ subcontrol-origin: padding; /* 和padding开始对齐*/ subcontrol-position: top left; background-color: yellow; } #groupBox_3{ padding-top: 5px; } #groupBox_3::title{ subcontrol-origin: content; /*与内容对齐*/ subcontrol-position: top left; background-color: blue; } #groupBox_4::title{ subcontrol-origin: border; /*与边框对齐*/ subcontrol-position: top left; background-color: green; }