我创建了一个gridlayout审查GUi窗口。我在底部添加了标题,作者,评论标签和LineEdit以及Quit按钮。当我执行脚本时,退出按钮没有显示在输出窗口中。
import sys
from PySide import QtGui,QtCore
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
title = QtGui.QLabel('Title')
author = QtGui.QLabel('Author')
review = QtGui.QLabel('Review')
titleEdit = QtGui.QLineEdit()
authorEdit = QtGui.QLineEdit()
reviewEdit = QtGui.QTextEdit()
btn = QtGui.QPushButton("Quit", self)
btn.resize(50,50)
btn.clicked.connect(QtCore.QCoreApplication.instance().quit)
grid = QtGui.QGridLayout()
grid.setSpacing(10)
grid.addWidget(title, 1, 0)
grid.addWidget(titleEdit, 1, 1)
grid.addWidget(author, 2, 0)
grid.addWidget(authorEdit, 2, 1)
grid.addWidget(review, 3, 0)
grid.addWidget(reviewEdit, 3, 1, 5, 1)
grid.addWidget(btn,6,1)
self.setLayout(grid)
self.setGeometry(300, 300, 350, 300)
self.setWindowTitle('Review')
self.show()
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
我无法找出问题所在。我在哪里做错了?
答案 0 :(得分:0)
将grid.addWidget(btn, 6, 1)
更改为grid.addWidget(btn, 8, 1)
。您的QTextEdit
以网格为单位具有高度5
;因此3 + 5 = 8
是第一个空位。