python - 如何在 PyQt5 中的现有主窗口位置(不是屏幕中心)放置新窗口?
问题描述
我有一个项目,用户按下一个打开一个新窗口的按钮。如何将我的新窗口设置为始终在主窗口位置顶部打开?(当用户移动窗口时不要在屏幕中心打开它,安装在主窗口位置的顶部)
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
class MainWindow(QtWidgets.QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.mainUI()
def mainUI(self):
self.setWindowTitle('Estetica Arch Bt.')
self.setGeometry(0,0,400,400)
self.button = QPushButton('Open',self)
self.button.clicked.connect(self.on_click_button)
self._main = QtWidgets.QWidget()
self.setCentralWidget(self._main)
layout = QtWidgets.QGridLayout(self._main)
layout.addWidget(self.button)
self.show()
@pyqtSlot()
def on_click_button(self):
self.pdw = ProjektDetailsWindow()
self.pdw.show()
class ProjektDetailsWindow(QWidget):
def __init__(self):
super().__init__()
self.projektdetails()
def projektdetails(self):
self.setFixedSize(200, 200)
self.show()
def main():
app = QApplication(sys.argv)
ex = MainWindow()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
解决方案
你可以move()
在你想要的地方新建一个窗口show()
。
@pyqtSlot()
def on_click_button(self):
self.pdw = ProjektDetailsWindow()
self.pdw.show()
self.pdw.move(self.pos())
推荐阅读
- css - 自动从 WordPress 页面中删除未使用的 CSS?
- java - 尝试创建新文件会引发 FileNotFoundException 但文件存在于同一包中
- html - 内容 CSS 和与 IE 的兼容性
- c# - 对 Task 对象的引用未指向新的 Task
- python - AttributeError: exp 在使用 scipy.io.loadmat 加载的数据上使用 numpy
- c# - 如何使用自动类型转换展开对象数组以进行函数调用?
- sql - SQL 将员工姓名和薪水列在另一个之下
- ios - Xcode 10 多个命令为 Pods 依赖构建错误
- postgresql - 刷新物化视图 CONCURRENTLY 导致表膨胀
- php - 单击下拉条目后过滤 html 表格结果