【发布时间】:2016-05-17 09:15:47
【问题描述】:
我在 Python 中构建了一个应用程序,使用 PyQt4 库作为我的 GUI。我的 GUI 在其上方绘制了一个图形和一些按钮。图表位于frame_B,图表上方的按钮(和LED)位于frame_A:
我在MainWindow 类中创建frame_A(以及frame_B):
class CustomMainWindow(QtGui.QMainWindow):
def __init__(self):
super(CustomMainWindow, self).__init__()
# Do some initialization stuff..
''''''
def initLayout(self):
# Create frame_A and its corresponding layout
frame_A = QtGui.QFrame(self)
setCustomSize(frame_A, 380,800)
self.layout_A = QtGui.QGridLayout()
frame_A.setLayout(self.layout_A)
# Create frame_B, and so forth..
''''''
def setButtons(self):
# Create btn01..
# Create btn02..
# Create btn03..
# Create btn04..
# Create btn05..
# Create led01..
# Add all buttons to the layout of frame_A:
self.layout_A.addWidget(self.btn01, *(0,0))
self.layout_A.addWidget(self.btn02, *(0,1))
self.layout_A.addWidget(self.btn03, *(0,2))
self.layout_A.addWidget(self.btn04, *(0,3))
self.layout_A.addWidget(self.btn05, *(0,4))
self.layout_A.addWidget(self.led01, *(0,5))
''''''
''''''
结果非常令人满意,如上图所示。当我放大我的窗口(通过简单的点击并用鼠标拖动)时,frame_A 和 frame_B 也会放大。那很好。我不想要任何其他方式。
但令我困扰的是frame_A 中的按钮被均匀分布以填充所有新空间。我更喜欢这样的行为:
任何人有一个聪明的想法来实现这一点?
【问题讨论】:
标签: python qt python-3.x pyqt pyqt4