Я ищу способ открыть QDialog widget
в центральной позиции главного окна. Я установил положение главного окна по центру.
centerPoint = qtw.QDesktopWidget().availableGeometry().center()
qtRectangle.moveCenter(centerPoint)
, чтобы переместить виджет диалога в положение главного окна. Я установил его
msgb.move(self.pos().x(), self.pos().y())
, диалоговое окно следует положение главного окна, но оно открывается в верхней левой части главного окна, как я могу изменить его положение в центре главного окна?
#!/usr/bin/env python
"""
startscreen
base window remit to specific tests
"""
import os
import sys
from PyQt5 import QtWidgets as qtw
from PyQt5 import QtCore as qtc
class Startscreen(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
# position
qtRectangle = self.frameGeometry()
centerPoint = qtw.QDesktopWidget().availableGeometry().center()
qtRectangle.moveCenter(centerPoint)
self.move(qtRectangle.topLeft())
# size
self.resize(700, 410)
# frame title
self.setWindowTitle("Lambda")
# heading
heading_label = qtw.QLabel("Lambda Version 1.0")
heading_label.setAlignment(qtc.Qt.AlignHCenter)
# active user
activeuser_label = qtw.QLabel('Benutzer: ' + os.getlogin())
activeuser_label.setStyleSheet("background-color: rgb(234, 246, 22)")
activeuser_label.setAlignment(qtc.Qt.AlignRight | qtc.Qt.AlignTop)
# groubox for widget positioning
self.groupbox = qtw.QGroupBox(self)
# groupbox.setAlignment(qtc.Qt.AlignHCenter)
# layout and widgets
vlayout = qtw.QVBoxLayout()
vlayout.setAlignment(qtc.Qt.AlignHCenter)
self.particlesize_radiobutton = qtw.QRadioButton("test1")
vlayout.addWidget(self.particlesize_radiobutton)
self.dimensionalchange_radiobutton = qtw.QRadioButton("test2")
vlayout.addWidget(self.dimensionalchange_radiobutton)
self.dimensionalchangecook_radiobutton = qtw.QRadioButton("test3")
vlayout.addWidget(self.dimensionalchangecook_radiobutton)
self.select_button = qtw.QPushButton('select')
vlayout.addWidget(self.select_button)
self.groupbox.setLayout(vlayout)
# mainlayout
main_layout = qtw.QFormLayout()
main_layout.addRow(activeuser_label)
main_layout.addRow(heading_label)
main_layout.setVerticalSpacing(40)
main_layout.addRow(self.groupbox)
self.setLayout(main_layout)
# functionality
self.select_button.clicked.connect(self.open_box)
self.show()
def open_box(self):
msgb = qtw.QMessageBox()
msgb.setWindowTitle("title")
msgb.setText("hier sthet was")
msgb.move(self.pos().x(), self.pos().y())
run = msgb.exec_()
# msgb = qtw.QMessageBox()
# msgb.addButton()
# if x open new windwo
#
if __name__ == '__main__':
app = qtw.QApplication(sys.argv)
w = Startscreen()
sys.exit(app.exec_())