我想在窗口中移动qazxsw poi的位置,但是qazxsw poi和qazxsw poi也被移动了。
我如何解决它,只是移动groupbox
的位置? (menubar
命令不起作用)
tools
试试吧:
GroupBox
move
更新
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
class Window(QtWidgets.QMainWindow):
def __init__(self):
super(Window, self).__init__()
V = QtWidgets.QApplication.desktop().screenGeometry()
h, w, x, y = V.height(), V.width(), 1000, 600
self.setGeometry(h/4, w/20, x, y)
self.setFixedSize(x, y)
self.setWindowTitle('Main Window')
OpenFile = QtWidgets.QAction('Open', self)
OpenFile.setShortcut('Ctrl+O')
OpenFile.setStatusTip('Open Restore File...')
self.statusBar()
mainMenu = self.menuBar()
fileMenu = mainMenu.addMenu('File')
fileMenu.addAction(OpenFile)
self.home()
def home(self):
self.tools_in_home()
self.show()
def tools_in_home(self):
self.groupBox = QtWidgets.QGroupBox('Test')
self.groupBox.setFixedSize(800, 400)
self.setContentsMargins(100, 100, 100, 100) # <=== HERE
hBoxLayout = QtWidgets.QHBoxLayout()
self.groupBox.setLayout(hBoxLayout)
self.setCentralWidget(self.groupBox)
def run():
app = QtWidgets.QApplication(sys.argv)
GUI = Window()
sys.exit(app.exec_())
if __name__ == '__main__':
run()
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
class Window(QtWidgets.QMainWindow):
def __init__(self):
super(Window, self).__init__()
V = QtWidgets.QApplication.desktop().screenGeometry()
h, w, x, y = V.height(), V.width(), 1000, 600
self.setGeometry(h/4, w/20, x, y)
self.setFixedSize(x, y)
# +++ vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
centralWidget = QtWidgets.QWidget()
self.setCentralWidget(centralWidget)
self.grid = QtWidgets.QGridLayout(centralWidget)
left, top, right, bottom = 100, 100, 100, 100
centralWidget.setContentsMargins(left, top, right, bottom)
# +++ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OpenFile = QtWidgets.QAction('Open', self)
OpenFile.setShortcut('Ctrl+O')
OpenFile.setStatusTip('Open Restore File...')
self.statusBar()
mainMenu = self.menuBar()
fileMenu = mainMenu.addMenu('File')
fileMenu.addAction(OpenFile)
self.home()
def home(self):
self.tools_in_home()
self.show()
def tools_in_home(self):
self.groupBox = QtWidgets.QGroupBox('Test')
self.groupBox.setFixedSize(800, 400)
self.grid.addWidget(self.groupBox)
def run():
app = QtWidgets.QApplication(sys.argv)
GUI = Window()
GUI.setWindowTitle('Main Window')
sys.exit(app.exec_())
if __name__ == '__main__':
run()