QPushButton 放在QFrame上 有边框显示出来,怎么去掉
时间: 2024-11-29 08:17:07 浏览: 114
QPushButton默认会有一个边框,如果你想在将其放在QFrame上并保持无边框效果,你可以通过设置QPushButton的一些样式属性来实现。这里是一些建议:
1. **直接设置样式**:
使用`setStyleSheet()`方法来改变按钮的样式,设置无边框和背景色透明或者其他自定义样式,例如:
```python
button = QPushButton()
button.setStyleSheet("border: none; background-color: transparent;")
```
2. **避免内嵌容器的边框**:
如果你在QFrame内部创建QPushButton,可以将两者都设置为无边框,并尝试将QPushButton放在QFrame的中心位置,使其看起来像是独立的元素:
```python
frame = QFrame()
frame.setFrameShape(QFrame.NoFrame) # 设置QFrame无边框
button = QPushButton(frame)
button.move(frame.width() // 2 - button.width() // 2,
frame.height() // 2 - button.height() // 2)
```
3. **使用窗口布局**:
如果你想要更精细地控制布局,可以考虑使用QGridLayout、QVBoxLayout或其他窗口布局管理器,并明确设置按钮的位置和大小。
阅读全文
相关推荐















