gpt4 book ai didi

python - Qgridlayout 控制widget的大小

转载 作者:行者123 更新时间:2023-12-01 06:33:31 26 4
gpt4 key购买 nike

我正在尝试将 Qgridlayout 用于我的 GUI。我希望减小 Qspin 的宽度,如图所示。有什么建议我该怎么做吗?谢谢

    layout.addWidget(checkBoxVBG,1,0)
layout.addWidget(checkBoxIREF,2,0)


layout.addWidget(boxVBG, 1, 1)
layout.addWidget(boxIREF, 2, 1)


layout.addWidget(checkBoxZERO_X,1,2)
layout.addWidget(checkBox4MOSC,2,2)


layout.addWidget(boxZERO_X, 1, 3)
layout.addWidget(box4MOSC, 2, 3)

enter image description here

最佳答案

您可以设置固定宽度和左对齐。

import sys

from PyQt5 import QtCore, QtGui, QtWidgets


class Widget(QtWidgets.QWidget):
def __init__(self, parent=None):
super().__init__(parent)

layout = QtWidgets.QGridLayout(self)

checkBoxVBG = QtWidgets.QCheckBox("VBG")
checkBoxIREF = QtWidgets.QCheckBox("IREF")
boxVBG = QtWidgets.QSpinBox()
boxIREF = QtWidgets.QSpinBox()
checkBoxZERO_X = QtWidgets.QCheckBox("ZERO X")
checkBox4MOSC = QtWidgets.QCheckBox("4MOSC")
boxZERO_X = QtWidgets.QSpinBox()
box4MOSC = QtWidgets.QSpinBox()

for spinbox in (boxVBG, boxIREF, boxZERO_X, box4MOSC):
spinbox.setFixedWidth(60)

layout.addWidget(checkBoxVBG, 1, 0)
layout.addWidget(checkBoxIREF, 2, 0)

layout.addWidget(boxVBG, 1, 1, alignment=QtCore.Qt.AlignLeft)
layout.addWidget(boxIREF, 2, 1, alignment=QtCore.Qt.AlignLeft)

layout.addWidget(checkBoxZERO_X, 1, 2)
layout.addWidget(checkBox4MOSC, 2, 2)

layout.addWidget(boxZERO_X, 1, 3, alignment=QtCore.Qt.AlignLeft)
layout.addWidget(box4MOSC, 2, 3, alignment=QtCore.Qt.AlignLeft)


if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
w = Widget()
w.show()
sys.exit(app.exec_())

关于python - Qgridlayout 控制widget的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59781117/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com