Qt RadioButtonqss文字居中
时间: 2024-05-12 16:14:18 浏览: 317
QT界面怎么使控件随窗口大小变化一直居中显示-百度经验1
可以通过设置样式表来实现RadioButton文字居中。以下是一个示例:
```
QRadioButton::indicator {
width: 20px;
height: 20px;
}
QRadioButton::indicator:checked {
image: url(:/images/radio_checked.png);
}
QRadioButton::indicator:unchecked {
image: url(:/images/radio_unchecked.png);
}
QRadioButton::indicator:checked:disabled {
image: url(:/images/radio_checked_disabled.png);
}
QRadioButton::indicator:unchecked:disabled {
image: url(:/images/radio_unchecked_disabled.png);
}
QRadioButton::indicator:hover {
border: none;
}
QRadioButton::indicator:checked:hover {
border: none;
}
QRadioButton::indicator:unchecked:hover {
border: none;
}
QRadioButton::indicator:checked:focus {
border: none;
}
QRadioButton::indicator:unchecked:focus {
border: none;
}
QRadioButton::indicator:checked:pressed {
border: none;
}
QRadioButton::indicator:unchecked:pressed {
border: none;
}
QRadioButton::indicator:checked:disabled:hover {
border: none;
}
QRadioButton::indicator:unchecked:disabled:hover {
border: none;
}
QRadioButton::indicator:checked:disabled:focus {
border: none;
}
QRadioButton::indicator:unchecked:disabled:focus {
border: none;
}
QRadioButton::indicator:checked:disabled:pressed {
border: none;
}
QRadioButton::indicator:unchecked:disabled:pressed {
border: none;
}
QRadioButton::indicator:checked:indeterminate {
image: url(:/images/radio_indeterminate.png);
}
QRadioButton::indicator:unchecked:indeterminate {
image: url(:/images/radio_indeterminate.png);
}
QRadioButton {
padding-left: 25px;
}
QRadioButton::indicator {
position: absolute;
top: 0px;
left: 0px;
}
```
在这个样式表中,我们将RadioButton的padding-left设置为25px,以便将RadioButton的左边距离留出一定的空间。然后,我们使用绝对定位来将RadioButton的指示器放在左侧,同时将其宽度和高度设置为20px。
最后,我们可以根据需要设置RadioButton的checked和unchecked状态下的图像,以及鼠标悬停、按下、失效等状态下的样式。
阅读全文