简体   繁体   English

PySide2 - 主要 Window 没有显示并说“窗口没有响应”

[英]PySide2 - Main Window not showing and saying “Window is not responding”

I have some trouble with pyside2... Before I got it to respond, but I can't right now.. I don't know why我在使用 pyside2 时遇到了一些问题......在我得到它回应之前,但我现在不能......我不知道为什么

Here's some code:这是一些代码:

main.py主文件

app = c.QApplication(c.sys.argv)
    splash_pix = c.QPixmap("animation.gif")
    splash = c.SplashScreen("animation.gif", c.Qt.WindowStaysOnTopHint)
    splash.show()
    app.processEvents()
    screen = app.primaryScreen()
    size = screen.size()
    main_window = c.Main(x=(size.width() // 2) - (500 // 2), y=(size.height() // 2) - (500 // 2))
    splash.finish(main_window)
    c.time.sleep(0.01)
    main_window.show()
    c.sys.exit(app.exec_())

I imported the packages "Main" is a class I made我导入的包“主要”是我制作的 class


class Main(QWidget):
    def __init__(self, x, y, width=500, height=500, parent=None):
        super().__init__()
        self.x, self.y, self.width, self.height = x, y, width, height
        self.setStyleSheet("background-color: rgba(255, 255, 255, 1);")
        self.setWindowTitle("Test")
        self.setGeometry(self.x, self.y, self.width, self.height)
        self.addWidgets()

    def addWidgets(self):
        self.welcome_label = QLabel("Test")
        self.welcome_label.setStyleSheet("QLabel {qproperty-alignment: AlignCenter; font-size: 30px; font-weight: 600;}")

        self.register_button = QPushButton("Register")
        self.register_button.setStyleSheet("QPushButton {background-color: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0.273, stop: 0 rgba(85,172,238,1), stop: 1 rgba(79, 165, 240, 1)); border-radius: 20px; color: white; font: bold 18px; min-width: 5em; min-height: 1.8em; padding: 1px;} QPushButton:hover {background-color: rgba(69, 131, 186, 1);}")
        self.register_button.clicked.connect(self.on_register)

        self.login_button = QPushButton("Login")
        self.login_button.setStyleSheet("QPushButton {background-color: qlineargradient(x1:0, y1:0, x2:1, y2:0.273, stop:0 rgba(85,172,238,1), stop:1 rgba(79, 165, 240, 1)); border-radius: 20px; color: white; font: bold 18px; min-width: 5em; min-height: 1.8em; padding: 1px;} QPushButton:hover {background-color: rgba(69, 131, 186, 1);}")
        self.login_button.clicked.connect(self.on_login)


        self.layout = QVBoxLayout()
        self.layout.addWidget(self.welcome_label)
        self.layout.addWidget(self.register_button)
        self.layout.addWidget(self.login_button)
        self.setLayout(self.layout)

I got the same problem with MacOS 11.0.1 Big Sur and PySide2 5.15.1 and 5.15.2 (it is mentioned in the internet that it was fixed for PyQt 5.15.2 but apparently this isn't the case for PySide2).我在 MacOS 11.0.1 Big Sur 和 PySide2 5.15.1 和 5.15.2 上遇到了同样的问题(互联网上提到它是为 PyQt 5.15.2 修复的,但显然这不是 PySide2 的情况)。 I confirm solution with QT_MAC_WANTS_LAYER, I did it this way:我用 QT_MAC_WANTS_LAYER 确认解决方案,我是这样做的:

import os
os.environ['QT_MAC_WANTS_LAYER'] = '1' 

Okay, nevermind, I found the answer... Big Sur apparently messes up with PyQT.好吧,没关系,我找到了答案……Big Sur 显然搞砸了 PyQT。 Fix here:https://forums.macrumors.com/threads/pyqt5-and-big-sur.2260773/ Basically run export QT_MAC_WANTS_LAYER=1 before running the program.在这里修复:https://forums.macrumors.com/threads/pyqt5-and-big-sur.2260773/基本上在运行程序之前运行export QT_MAC_WANTS_LAYER=1 Such a weird bug..这么奇怪的bug。。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM