pyqt QPushButton放在界面右下角
时间: 2023-11-14 18:59:26 浏览: 102
可以使用布局来实现将QPushButton放在界面的右下角。以下是使用QVBoxLayout和QHBoxLayout的示例代码:
```python
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout, QHBoxLayout
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
# 创建QPushButton
btn = QPushButton('Button', self)
# 创建两个布局
vbox = QVBoxLayout()
hbox = QHBoxLayout()
# 将QPushButton添加到布局中
hbox.addStretch(1)
hbox.addWidget(btn)
vbox.addStretch(1)
vbox.addLayout(hbox)
# 设置窗口的布局
self.setLayout(vbox)
self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('QPushButton')
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
```
在这个示例中,我们将一个QPushButton添加到了一个QHBoxLayout中,并使用addStretch()方法将其放在了右侧。然后,我们创建了一个QVBoxLayout,并将QHBoxLayout添加到其中,这样我们就可以将QPushButton放在界面的右下角。
阅读全文
相关推荐


















