pyqt5:启动应用程序时出现qt.qpa.xcb错误

时间:2019-07-15 13:08:49

标签: python python-3.x pyqt5 pyqt4 xcb

我正在将应用程序从pyqt4迁移到pyqt5。 除我一直在应用程序启动时遇到的这个问题之外,大多数方法都可以正常工作:

$ python3 /tmp/loading.py 
qt.qpa.xcb: failed to initialize XRandr
qt.qpa.xcb: X server does not support XInput 2

我的应用程序有一个正在加载某些东西的加载屏幕:

import sys
import time

from PyQt5 import QtGui, QtCore, QtWidgets

from resources import Images


class LoadingScreen(QtWidgets.QMainWindow):
    def __init__(self):
        super(LoadingScreen, self).__init__()
        self.setWindowTitle('Loading MyApp...')
        self.setWindowIcon(QtGui.QIcon(Images.LOGO))
        self.setMaximumSize(600, 338)
        self.setMinimumSize(600, 338)
        self.setWindowFlags(QtCore.Qt.FramelessWindowHint)

        self.palette = QtGui.QPalette()
        pixmap = QtGui.QPixmap(Images.LOADING_BACKGROUND)
        brush = QtGui.QBrush(pixmap.scaled(self.size(), QtCore.Qt.IgnoreAspectRatio))
        self.palette.setBrush(QtGui.QPalette.Background, brush)
        self.setPalette(self.palette)

        center = QtWidgets.QDesktopWidget().availableGeometry().center()
        self.move(center)


app = QtWidgets.QApplication(sys.argv)
loading_screen = LoadingScreen()
loading_screen.show()
time.sleep(5)
loading_screen.close()

在pyqt4中它可以正常工作,我看到了这个简单的加载窗口,然后将其关闭。 另一方面,在pyqt5中,我在shell中遇到了以上错误,并且窗口从不显示自身。

EDIT1

app = QtWidgets.QApplication(sys.argv)
loading_screen = LoadingScreen()
loading_screen.show()
foo()
loading_screen.close()
sys.exit(app.exec_())

EDIT2

import sys
import time

from PyQt4 import QtGui, QtCore

from drivertest.ui.gui.resources.resources import Images


class Form(QtGui.QDialog):
    """ Just a simple dialog with a couple of widgets
    """
    def __init__(self, parent=None):
        super(Form, self).__init__(parent)
        self.browser = QtGui.QTextBrowser()
        self.setWindowTitle('Just a dialog')
        self.lineedit = QtGui.QLineEdit("Write something and press Enter")
        self.lineedit.selectAll()
        layout = QtGui.QVBoxLayout()
        layout.addWidget(self.browser)
        layout.addWidget(self.lineedit)
        self.setLayout(layout)
        self.lineedit.setFocus()

    def foo(self):
        for _ in range(100000000):
            pass


class LoadingScreen(QtGui.QMainWindow):
    def __init__(self):
        super(LoadingScreen, self).__init__()
        self.setWindowTitle('Loading DriVerTest...')
        self.setWindowIcon(QtGui.QIcon(Images.LOGO))
        self.setMaximumSize(600, 338)
        self.setMinimumSize(600, 338)
        self.setWindowFlags(QtCore.Qt.FramelessWindowHint)

        self.palette = QtGui.QPalette()
        pixmap = QtGui.QPixmap(Images.LOADING_BACKGROUND)
        brush = QtGui.QBrush(pixmap.scaled(self.size(), QtCore.Qt.IgnoreAspectRatio))
        self.palette.setBrush(QtGui.QPalette.Background, brush)
        self.setPalette(self.palette)

        center = QtGui.QDesktopWidget().availableGeometry().center()
        self.move(center)



app = QtGui.QApplication(sys.argv)
loading_screen = LoadingScreen()
loading_screen.show()

g = Form()
g.foo()

loading_screen.close()

g.show()

sys.exit(app.exec_())

0 个答案:

没有答案