QRadioButton { text-align: center;}没有居中
时间: 2024-05-16 19:12:24 浏览: 9
如果QRadioButton没有居中,可以尝试使用以下CSS样式来居中:
```
QRadioButton {
text-align: center;
}
QRadioButton::indicator {
subcontrol-origin: padding;
subcontrol-position: center center;
}
```
这样应该就可以实现QRadioButton的居中了。
相关问题
QRadioButton { text-align: center;}字体没有居中
可以尝试添加以下CSS样式来实现单选按钮文本的居中显示:
```
QRadioButton::indicator {
width: 20px;
height: 20px;
}
QRadioButton::indicator:checked {
background-color: #0078d7;
border: 1px solid #0078d7;
}
QRadioButton::indicator:checked:disabled {
background-color: #ccc;
border: 1px solid #ccc;
}
QRadioButton::indicator:unchecked:disabled {
background-color: #fff;
border: 1px solid #ccc;
}
QRadioButton::indicator:unchecked {
background-color: #fff;
border: 1px solid #ccc;
}
QRadioButton::indicator:checked:pressed {
background-color: #005bae;
border: 1px solid #005bae;
}
QRadioButton::indicator:unchecked:pressed {
background-color: #ccc;
border: 1px solid #ccc;
}
QRadioButton {
color: #333;
font-size: 16px;
font-weight: normal;
padding-left: 26px;
padding-right: 4px;
padding-top: 4px;
padding-bottom: 4px;
border-radius: 10px;
background-color: #fff;
}
QRadioButton::indicator:checked {
image: url(./assets/checked.png);
}
QRadioButton::indicator:unchecked {
image: url(./assets/unchecked.png);
}
QRadioButton::indicator:checked:hover, QRadioButton::indicator:unchecked:hover {
border: 1px solid #0078d7;
}
QRadioButton::indicator:checked:focus, QRadioButton::indicator:unchecked:focus {
border: 1px solid #0078d7;
}
```
其中,`padding-left` 和 `padding-right` 属性可以控制文本左右两侧的间距,从而实现居中显示。您可以根据具体情况调整这些值以达到最佳效果。
QRadioButton { text-align: center; 没效
如果你想在QRadioButtons上居中文本,你可以使用CSS样式表来实现。以下是一个例子:
```python
radio_button.setStyleSheet("QRadioButton::indicator { width: 20px; height: 20px; } \
QRadioButton::indicator::unchecked { \
image:url('unchecked.png'); \
} \
QRadioButton::indicator::checked { \
image:url('checked.png'); \
} \
QRadioButton { \
padding-left: 25px; \
font-size: 16px; \
color: #333333; \
text-align: center; \
}")
```
在这个例子中,我们设置了一个样式表来定义QRadioButton的外观和行为。我们使用了"text-align: center"来居中文本。请注意,样式表中的"padding-left"值必须大于或等于指示器的宽度,以使文本居中。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)