У меня есть это окно, которое mainlayout представляет собой QVBoxlayout
с вложенным QHBoxlayout
Сверху a установили две метки, по некоторым причинам
pressen_label = qtw.QLabel("Choose A")
метка меняет свою позицию после окна перемещается или изменяется с помощью мыши.
перед перемещением / изменяет размер окна с помощью мыши
после перемещения окна
Как заблокировать положение этикетки, чтобы оно не двигалось?
pressen_label = qtw.QLabel("Choose A")
quality_label = qtw.QLabel("Choose B")
hblayout_labelcombo = qtw.QHBoxLayout()
hblayout_labelcombo.addWidget(pressen_label)
hblayout_labelcombo.addStretch(1)
hblayout_labelcombo.addWidget(quality_label)
hblayout_labelcombo.addStretch(10)
hblayout_labelcombo.setAlignment(qtc.Qt.AlignTop)
полный код
#!/usr/bin/env python
"""
template interface
"""
import sys
from PyQt5 import QtWidgets as qtw
from PyQt5 import QtCore as qtc
from PyQt5 import QtGui as qtg
class SwellingwindowParent(qtw.QWidget):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# your code will go here
# position
qtRectangle = self.frameGeometry()
centerPoint = qtw.QDesktopWidget().availableGeometry().center()
qtRectangle.moveTop(100)
# size
self.resize(1400, 910)
# frame title
self.setWindowTitle("Parent Window")
# widgets
# combobox label and layout
pressen_label = qtw.QLabel("Choose A")
quality_label = qtw.QLabel("Choose B")
hblayout_labelcombo = qtw.QHBoxLayout()
hblayout_labelcombo.addWidget(pressen_label)
hblayout_labelcombo.addStretch(1)
hblayout_labelcombo.addWidget(quality_label)
hblayout_labelcombo.addStretch(10)
hblayout_labelcombo.setAlignment(qtc.Qt.AlignTop)
# combobox widget and layout
comobox_selectpressen = qtw.QComboBox()
comobox_selectpressen.setFixedWidth(130)
comobox_selectquality = qtw.QComboBox()
comobox_selectquality.setFixedWidth(130)
hblayout_widgetcombobox = qtw.QHBoxLayout()
hblayout_widgetcombobox.addWidget(comobox_selectpressen)
hblayout_widgetcombobox.addStretch(1)
hblayout_widgetcombobox.addWidget(comobox_selectquality)
hblayout_widgetcombobox.addStretch(30)
hblayout_widgetcombobox.setAlignment(qtc.Qt.AlignTop)
# mss
heading_messschieber = qtw.QLabel("Mss stuff")
button_messschiber = qtw.QPushButton("mss start")
# M
messchiber_heading = qtw.QLabel("want to start msss ?")
hblayout_labelmsslayout = qtw.QHBoxLayout()
hblayout_labelmsslayout.addWidget(messchiber_heading)
hblayout_labelmsslayout.addStretch(2)
hblayout_labelmsslayout.addWidget(quality_label)
hblayout_labelmsslayout.addStretch(30)
msss_messuungstartenbutton = qtw.QPushButton("msss start")
hblayout_mssbuttonlayout = qtw.QHBoxLayout()
hblayout_mssbuttonlayout.addWidget(msss_messuungstartenbutton)
hblayout_mssbuttonlayout.addStretch(2)
hblayout_mssbuttonlayout.addWidget(quality_label)
hblayout_mssbuttonlayout.addStretch(30)
# spacer set custum vertical space
verticalSpacer1 = qtw.QSpacerItem(10, 10, qtw.QSizePolicy.Minimum, vPolicy=qtw.QSizePolicy.Fixed)
verticalSpacer2 = qtw.QSpacerItem(10, 5, qtw.QSizePolicy.Minimum, vPolicy=qtw.QSizePolicy.Fixed)
verticalSpacer3 = qtw.QSpacerItem(10, 50, qtw.QSizePolicy.Minimum, vPolicy=qtw.QSizePolicy.Fixed)
verticalSpacer4 = qtw.QSpacerItem(3, 1, vPolicy=qtw.QSizePolicy.Fixed)
# main layout
mainlayout = qtw.QVBoxLayout()
mainlayout.setAlignment(qtc.Qt.AlignTop) # needed for custom spacers
mainlayout.addSpacerItem(verticalSpacer1)
mainlayout.addLayout(hblayout_labelcombo)
mainlayout.addSpacerItem(verticalSpacer2)
mainlayout.addLayout(hblayout_widgetcombobox)
mainlayout.addSpacerItem(verticalSpacer3)
mainlayout.addLayout(hblayout_labelmsslayout)
mainlayout.addLayout(hblayout_mssbuttonlayout)
# mainlayout.addSpacerItem(verticalSpacer1)
self.setLayout(mainlayout)
# your code ends here
self.show()
if __name__ == '__main__':
app = qtw.QApplication(sys.argv)
w = SwellingwindowParent()
sys.exit(app.exec_())