Я хочу установить пользовательские разделители для отдельного разделения виджетов. Я установил 3 проставки, которые должны по-разному расширяться в вертикальном направлении, но расстояние между виджетами остается одинаковым.
verticalSpacer1 = qtw.QSpacerItem(1, 40, qtw.QSizePolicy.Minimum,
vPolicy=qtw.QSizePolicy.Expanding)
и
verticalSpacer2 = qtw.QSpacerItem(10, 3, qtw.QSizePolicy.Minimum,
vPolicy=qtw.QSizePolicy.Expanding)
Похоже, VBoxLayout занимает только параметры одной проставки.
#!/usr/bin/env python
"""
file
"""
import os
import sys
from PyQt5 import QtWidgets as qtw
from PyQt5 import QtCore as qtc
from PyQt5 import QtGui as qtg
class ChooseTest(qtw.QWidget):
"""
remit to one of three tests if widgets toggled/clicked
hide its self after
"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# your code will go here
# interface not move
self.setWindowFlags(qtc.Qt.FramelessWindowHint| qtc.Qt.SubWindow)
self.setWindowModality(qtc.Qt.ApplicationModal)
# position
qtRectangle = self.frameGeometry()
centerPoint = qtw.QDesktopWidget().availableGeometry().center()
qtRectangle.moveCenter(centerPoint)
# self.move(qtRectangle.topLeft())
# size
self.resize(400, 310)
# heading
heading_label = qtw.QLabel("Heading")
heading_label.setAlignment(qtc.Qt.AlignHCenter)
# widgets
comobox_selectpressen = qtw.QComboBox()
comobox_selectpressen.setFixedWidth(130)
comobox_selectquality = qtw.QComboBox()
comobox_selectquality.setFixedWidth(130)
start_test_label = qtw.QLabel("beginn")
self.start_button = qtw.QPushButton("beginn 1")
self.start_button.setFixedWidth(130)
self.back_button = qtw.QPushButton("back to")
self.back_button.setFixedWidth(130)
# nested layout
hblayout_combo = qtw.QHBoxLayout()
hblayout_combo.addStretch(2)
hblayout_combo.addWidget(comobox_selectpressen)
hblayout_combo.addStretch(1)
hblayout_combo.addWidget(comobox_selectquality)
hblayout_combo.addStretch(2)
# start_button layout
hlayout_startbutton = qtw.QHBoxLayout()
hlayout_startbutton.addStretch(1)
hlayout_startbutton.addWidget(self.start_button)
hlayout_startbutton.addStretch(1)
# back_button layout
hlayout_backbutton = qtw.QHBoxLayout()
hlayout_backbutton.addStretch(1)
hlayout_backbutton.addWidget(self.back_button)
hlayout_backbutton.addStretch(1)
# spacer
verticalSpacer1 = qtw.QSpacerItem(1, 40, qtw.QSizePolicy.Minimum, vPolicy=qtw.QSizePolicy.Expanding)
verticalSpacer2 = qtw.QSpacerItem(10, 3, qtw.QSizePolicy.Minimum, vPolicy=qtw.QSizePolicy.Expanding)
verticalSpacer3 = qtw.QSpacerItem(3, 4, vPolicy=qtw.QSizePolicy.Expanding)
# @spacer = new QSpacerItem(40, 20, QSizePolicy::Minimum, QSizePolicy::Expanding);@
# mainlayout
main_layout = qtw.QVBoxLayout()
main_layout.addWidget(heading_label)
main_layout.addSpacerItem(verticalSpacer2)
main_layout.addLayout(hblayout_combo)
main_layout.addSpacerItem(verticalSpacer1)
main_layout.addLayout(hlayout_startbutton)
main_layout.addItem(verticalSpacer3)
main_layout.addLayout(hlayout_backbutton)
self.setLayout(main_layout)
# functionality
self.show()
if __name__ == '__main__':
app = qtw.QApplication(sys.argv)
w = ChooseTest()
sys.exit(app.exec_())