在我的示例程序中,我想隐藏hbox。但是我找不到任何方法在pyqt4中隐藏hbox。请任何人帮助我如何隐藏水平框。提前谢谢
下面是我的代码:
import sys
from PyQt4 import QtGui
global payments
payments = False
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
self.grid = QtGui.QGridLayout()
self.hbox = QtGui.QHBoxLayout()
self.cash = QtGui.QPushButton("cash")
self.card = QtGui.QPushButton("card")
self.wallet = QtGui.QPushButton("wallet")
self.hbox.addWidget(self.cash)
self.hbox.addWidget(self.card)
self.hbox.addWidget(self.wallet)
self.paybtn = QtGui.QPushButton("pay")
self.paybtn.clicked.connect(self.show_payments)
self.grid.addWidget(self.paybtn,1,0)
self.setLayout(self.grid)
self.setGeometry(300, 300, 500,500)
self.show()
def show_payments(self):
global payments
payments = not payments
print payments
if payments:
self.paybtn.setText('Edit Order')
self.grid.addLayout(self.hbox,0,0)
else:
self.paybtn.setText('Pay')
#here i want to hide the self.hbox
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
ex.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
布局的功能是管理其他小部件的位置和大小,您的任务不是隐藏。相反,您必须创建一个小部件,其中hbox带有按钮,并且该小部件在网格布局中设置它,因此只需要隐藏或显示新的小部件
相关问题 更多 >
编程相关推荐