简体   繁体   English

Raspbian 上的 PyQt5:不显示 QWidgets 的背景颜色

[英]PyQt5 on Raspbian: Background color of QWidgets is not displayed

I've compiled and installed PyQt5 on a Raspberry Pi 3B+ running Raspbian Buster like described here .我已经编制并在树莓派3B +安装PyQt5运行Raspbian巴斯特等中描述的在这里 It took a few hours, but it worked.花了几个小时,但它奏效了。 Afterwards I uploaded my simple PyQt example program consisting of 2 files ( main.py and mainwindow.ui ).之后,我上传了由 2 个文件( main.pymainwindow.ui )组成的简单 PyQt 示例程序。

The red background color set for QProgressBar and QPushButton are displayed in different shades of red (?) on my PC running Ubuntu 18.04 LTS, but on the Raspberry Pi it is not displayed at all.QProgressBarQPushButton设置的红色背景颜色在运行 Ubuntu 18.04 LTS 的 PC 上以不同深浅的红色 (?) 显示,但在 Raspberry Pi 上根本不显示。

Terminal output on Raspbian Buster: Raspbian Buster 上的终端输出:

libEGL warning: DRI2: failed to authenticate
qt5ct: using qt5ct plugin
qt5ct: D-Bus global menu: no

Screenshot on Ubuntu 18.04 LTS: Ubuntu 18.04 LTS 上的屏幕截图: Ubuntu 18.04 LTS 上简单 PyQt 示例程序的屏幕截图

Screenshot on Raspbian Buster: Raspbian Buster 上的截图: Raspbian Buster 上简单 PyQt 示例程序的屏幕截图

Why is the red background color not displayed on Raspbian Buster?为什么在 Raspbian Buster 上不显示红色背景色?

main.py主文件

import sys
from pathlib import Path
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5.QtGui import QColor
from PyQt5.uic import loadUi


class MainWindow(QMainWindow):
    def __init__(self, parent=None):
        super().__init__(parent)
        ui_file = (Path(__file__).parent / "mainwindow.ui").resolve()
        loadUi(ui_file, self)
        self.progressBar.setStyleSheet(f"background-color: {QColor('red').name()}")


def main():
    app = QApplication(sys.argv)
    main_window = MainWindow()
    main_window.show()
    sys.exit(app.exec_())


if __name__ == "__main__":
    main()

mainwindow.ui主窗口.ui

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>800</width>
    <height>200</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <property name="locale">
   <locale language="English" country="UnitedKingdom"/>
  </property>
  <widget class="QWidget" name="centralwidget">
   <layout class="QGridLayout" name="gridLayout_2">
    <item row="0" column="0">
     <layout class="QGridLayout" name="gridLayout">
      <item row="0" column="0">
       <widget class="QProgressBar" name="progressBar">
        <property name="value">
         <number>0</number>
        </property>
       </widget>
      </item>
      <item row="0" column="1">
       <widget class="QPushButton" name="pushButton">
        <property name="minimumSize">
         <size>
          <width>200</width>
          <height>0</height>
         </size>
        </property>
        <property name="styleSheet">
         <string notr="true">background-color: red;</string>
        </property>
        <property name="text">
         <string>Button</string>
        </property>
       </widget>
      </item>
     </layout>
    </item>
   </layout>
  </widget>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>800</width>
     <height>28</height>
    </rect>
   </property>
  </widget>
  <widget class="QStatusBar" name="statusbar"/>
 </widget>
 <resources/>
 <connections/>
</ui>

Terminal output on Raspbian Buster after setting export QT_DEBUG_PLUGINS=1 :设置export QT_DEBUG_PLUGINS=1后 Raspbian Buster 上的终端输出:

QFactoryLoader::QFactoryLoader() checking directory path "/usr/lib/arm-linux-gnueabihf/qt5/plugins/platforms" ...
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/arm-linux-gnueabihf/qt5/plugins/platforms/libqeglfs.so"
Found metadata in lib /usr/lib/arm-linux-gnueabihf/qt5/plugins/platforms/libqeglfs.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "eglfs"
        ]
    },
    "className": "QEglFSIntegrationPlugin",
    "debug": false,
    "version": 330499
}


Got keys from plugin meta data ("eglfs")
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/arm-linux-gnueabihf/qt5/plugins/platforms/libqlinuxfb.so"
Found metadata in lib /usr/lib/arm-linux-gnueabihf/qt5/plugins/platforms/libqlinuxfb.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "linuxfb"
        ]
    },
    "className": "QLinuxFbIntegrationPlugin",
    "debug": false,
    "version": 330499
}


Got keys from plugin meta data ("linuxfb")
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/arm-linux-gnueabihf/qt5/plugins/platforms/libqminimal.so"
Found metadata in lib /usr/lib/arm-linux-gnueabihf/qt5/plugins/platforms/libqminimal.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "minimal"
        ]
    },
    "className": "QMinimalIntegrationPlugin",
    "debug": false,
    "version": 330499
}


Got keys from plugin meta data ("minimal")
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/arm-linux-gnueabihf/qt5/plugins/platforms/libqminimalegl.so"
Found metadata in lib /usr/lib/arm-linux-gnueabihf/qt5/plugins/platforms/libqminimalegl.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "minimalegl"
        ]
    },
    "className": "QMinimalEglIntegrationPlugin",
    "debug": false,
    "version": 330499
}


Got keys from plugin meta data ("minimalegl")
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/arm-linux-gnueabihf/qt5/plugins/platforms/libqoffscreen.so"
Found metadata in lib /usr/lib/arm-linux-gnueabihf/qt5/plugins/platforms/libqoffscreen.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "offscreen"
        ]
    },
    "className": "QOffscreenIntegrationPlugin",
    "debug": false,
    "version": 330499
}


Got keys from plugin meta data ("offscreen")
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/arm-linux-gnueabihf/qt5/plugins/platforms/libqvnc.so"
Found metadata in lib /usr/lib/arm-linux-gnueabihf/qt5/plugins/platforms/libqvnc.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "vnc"
        ]
    },
    "className": "QVncIntegrationPlugin",
    "debug": false,
    "version": 330499
}


Got keys from plugin meta data ("vnc")
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/arm-linux-gnueabihf/qt5/plugins/platforms/libqxcb.so"
Found metadata in lib /usr/lib/arm-linux-gnueabihf/qt5/plugins/platforms/libqxcb.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "xcb"
        ]
    },
    "className": "QXcbIntegrationPlugin",
    "debug": false,
    "version": 330499
}


Got keys from plugin meta data ("xcb")
QFactoryLoader::QFactoryLoader() checking directory path "/usr/bin/platforms" ...
loaded library "/usr/lib/arm-linux-gnueabihf/qt5/plugins/platforms/libqxcb.so"
loaded library "Xcursor"
QFactoryLoader::QFactoryLoader() checking directory path "/usr/lib/arm-linux-gnueabihf/qt5/plugins/xcbglintegrations" ...
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/arm-linux-gnueabihf/qt5/plugins/xcbglintegrations/libqxcb-egl-integration.so"
Found metadata in lib /usr/lib/arm-linux-gnueabihf/qt5/plugins/xcbglintegrations/libqxcb-egl-integration.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.Xcb.QXcbGlIntegrationFactoryInterface.5.5",
    "MetaData": {
        "Keys": [
            "xcb_egl"
        ]
    },
    "className": "QXcbEglIntegrationPlugin",
    "debug": false,
    "version": 330499
}


Got keys from plugin meta data ("xcb_egl")
QFactoryLoader::QFactoryLoader() checking directory path "/usr/bin/xcbglintegrations" ...
loaded library "/usr/lib/arm-linux-gnueabihf/qt5/plugins/xcbglintegrations/libqxcb-egl-integration.so"
libEGL warning: DRI2: failed to authenticate
QFactoryLoader::QFactoryLoader() checking directory path "/usr/lib/arm-linux-gnueabihf/qt5/plugins/platformthemes" ...
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/arm-linux-gnueabihf/qt5/plugins/platformthemes/libqgtk2.so"
Found metadata in lib /usr/lib/arm-linux-gnueabihf/qt5/plugins/platformthemes/libqgtk2.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformThemeFactoryInterface.5.1",
    "MetaData": {
        "Keys": [
            "gtk2"
        ]
    },
    "className": "QGtk2ThemePlugin",
    "debug": false,
    "version": 330499
}


Got keys from plugin meta data ("gtk2")
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/arm-linux-gnueabihf/qt5/plugins/platformthemes/libqgtk3.so"
Found metadata in lib /usr/lib/arm-linux-gnueabihf/qt5/plugins/platformthemes/libqgtk3.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformThemeFactoryInterface.5.1",
    "MetaData": {
        "Keys": [
            "gtk3"
        ]
    },
    "className": "QGtk3ThemePlugin",
    "debug": false,
    "version": 330499
}


Got keys from plugin meta data ("gtk3")
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/arm-linux-gnueabihf/qt5/plugins/platformthemes/libqt5ct.so"
Found metadata in lib /usr/lib/arm-linux-gnueabihf/qt5/plugins/platformthemes/libqt5ct.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformThemeFactoryInterface.5.1",
    "MetaData": {
        "Keys": [
            "qt5ct"
        ]
    },
    "className": "Qt5CTPlatformThemePlugin",
    "debug": false,
    "version": 330499
}


Got keys from plugin meta data ("qt5ct")
QFactoryLoader::QFactoryLoader() checking directory path "/usr/bin/platformthemes" ...
loaded library "/usr/lib/arm-linux-gnueabihf/qt5/plugins/platformthemes/libqt5ct.so"
qt5ct: using qt5ct plugin
QFactoryLoader::QFactoryLoader() checking directory path "/usr/lib/arm-linux-gnueabihf/qt5/plugins/styles" ...
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/arm-linux-gnueabihf/qt5/plugins/styles/libbb10styleplugin.so"
Found metadata in lib /usr/lib/arm-linux-gnueabihf/qt5/plugins/styles/libbb10styleplugin.so, metadata=
{
    "IID": "org.qt-project.Qt.QStyleFactoryInterface",
    "MetaData": {
        "Keys": [
            "bb10bright",
            "bb10dark"
        ]
    },
    "className": "QBB10StylePlugin",
    "debug": false,
    "version": 330499
}


Got keys from plugin meta data ("bb10bright", "bb10dark")
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/arm-linux-gnueabihf/qt5/plugins/styles/libqcleanlooksstyle.so"
Found metadata in lib /usr/lib/arm-linux-gnueabihf/qt5/plugins/styles/libqcleanlooksstyle.so, metadata=
{
    "IID": "org.qt-project.Qt.QStyleFactoryInterface",
    "MetaData": {
        "Keys": [
            "cleanlooks"
        ]
    },
    "className": "QCleanlooksStylePlugin",
    "debug": false,
    "version": 330499
}


Got keys from plugin meta data ("cleanlooks")
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/arm-linux-gnueabihf/qt5/plugins/styles/libqgtk2style.so"
Found metadata in lib /usr/lib/arm-linux-gnueabihf/qt5/plugins/styles/libqgtk2style.so, metadata=
{
    "IID": "org.qt-project.Qt.QStyleFactoryInterface",
    "MetaData": {
        "Keys": [
            "gtk2"
        ]
    },
    "className": "QGtk2StylePlugin",
    "debug": false,
    "version": 330499
}


Got keys from plugin meta data ("gtk2")
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/arm-linux-gnueabihf/qt5/plugins/styles/libqmotifstyle.so"
Found metadata in lib /usr/lib/arm-linux-gnueabihf/qt5/plugins/styles/libqmotifstyle.so, metadata=
{
    "IID": "org.qt-project.Qt.QStyleFactoryInterface",
    "MetaData": {
        "Keys": [
            "motif",
            "cde"
        ]
    },
    "className": "QMotifStylePlugin",
    "debug": false,
    "version": 330499
}


Got keys from plugin meta data ("motif", "cde")
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/arm-linux-gnueabihf/qt5/plugins/styles/libqplastiquestyle.so"
Found metadata in lib /usr/lib/arm-linux-gnueabihf/qt5/plugins/styles/libqplastiquestyle.so, metadata=
{
    "IID": "org.qt-project.Qt.QStyleFactoryInterface",
    "MetaData": {
        "Keys": [
            "plastique"
        ]
    },
    "className": "QPlastiqueStylePlugin",
    "debug": false,
    "version": 330499
}


Got keys from plugin meta data ("plastique")
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/arm-linux-gnueabihf/qt5/plugins/styles/libqt5ct-style.so"
Found metadata in lib /usr/lib/arm-linux-gnueabihf/qt5/plugins/styles/libqt5ct-style.so, metadata=
{
    "IID": "org.qt-project.Qt.QStyleFactoryInterface",
    "MetaData": {
        "Keys": [
            "qt5ct-style"
        ]
    },
    "className": "Qt5CTStylePlugin",
    "debug": false,
    "version": 330499
}


Got keys from plugin meta data ("qt5ct-style")
QFactoryLoader::QFactoryLoader() checking directory path "/usr/bin/styles" ...
QFactoryLoader::QFactoryLoader() checking directory path "/usr/lib/arm-linux-gnueabihf/qt5/plugins/platforminputcontexts" ...
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/arm-linux-gnueabihf/qt5/plugins/platforminputcontexts/libcomposeplatforminputcontextplugin.so"
Found metadata in lib /usr/lib/arm-linux-gnueabihf/qt5/plugins/platforminputcontexts/libcomposeplatforminputcontextplugin.so, metadata=
{
    "IID": "org.qt-project.Qt.QPlatformInputContextFactoryInterface.5.1",
    "MetaData": {
        "Keys": [
            "compose",
            "xim"
        ]
    },
    "className": "QComposePlatformInputContextPlugin",
    "debug": false,
    "version": 330499
}


Got keys from plugin meta data ("compose", "xim")
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/arm-linux-gnueabihf/qt5/plugins/platforminputcontexts/libibusplatforminputcontextplugin.so"
Found metadata in lib /usr/lib/arm-linux-gnueabihf/qt5/plugins/platforminputcontexts/libibusplatforminputcontextplugin.so, metadata=
{
    "IID": "org.qt-project.Qt.QPlatformInputContextFactoryInterface.5.1",
    "MetaData": {
        "Keys": [
            "ibus"
        ]
    },
    "className": "QIbusPlatformInputContextPlugin",
    "debug": false,
    "version": 330499
}


Got keys from plugin meta data ("ibus")
QFactoryLoader::QFactoryLoader() checking directory path "/usr/bin/platforminputcontexts" ...
loaded library "/usr/lib/arm-linux-gnueabihf/qt5/plugins/platforminputcontexts/libcomposeplatforminputcontextplugin.so"
loaded library "/usr/lib/arm-linux-gnueabihf/qt5/plugins/styles/libqt5ct-style.so"
loaded library "/usr/lib/arm-linux-gnueabihf/qt5/plugins/styles/libqgtk2style.so"
Cannot load library gtk-x11-2.0: (gtk-x11-2.0: Kann die Shared-Object-Datei nicht öffnen: Datei oder Verzeichnis nicht gefunden)
qt5ct: D-Bus global menu: no
QFactoryLoader::QFactoryLoader() checking directory path "/usr/lib/arm-linux-gnueabihf/qt5/plugins/iconengines" ...
QFactoryLoader::QFactoryLoader() looking at "/usr/lib/arm-linux-gnueabihf/qt5/plugins/iconengines/libqsvgicon.so"
Found metadata in lib /usr/lib/arm-linux-gnueabihf/qt5/plugins/iconengines/libqsvgicon.so, metadata=
{
    "IID": "org.qt-project.Qt.QIconEngineFactoryInterface",
    "MetaData": {
        "Keys": [
            "svg",
            "svgz",
            "svg.gz"
        ]
    },
    "className": "QSvgIconPlugin",
    "debug": false,
    "version": 330499
}


Got keys from plugin meta data ("svg", "svgz", "svg.gz")
QFactoryLoader::QFactoryLoader() checking directory path "/usr/bin/iconengines" ...
QFactoryLoader::QFactoryLoader() checking directory path "/usr/lib/arm-linux-gnueabihf/qt5/plugins/accessible" ...
QFactoryLoader::QFactoryLoader() checking directory path "/usr/bin/accessible" ...
QFactoryLoader::QFactoryLoader() checking directory path "/usr/lib/arm-linux-gnueabihf/qt5/plugins/accessiblebridge" ...
QFactoryLoader::QFactoryLoader() checking directory path "/usr/bin/accessiblebridge" ...

I've been fighting similar problems today (which is how I found your post).我今天一直在与类似的问题作斗争(这就是我发现你的帖子的方式)。 To get rid of the libEGL warning run raspi-config and select the "Full KMS" option from Advanced Options->GL Driver (then reboot).要摆脱 libEGL 警告,请运行 raspi-config 并从 Advanced Options->GL Driver 中选择“Full KMS”选项(然后重新启动)。 That likely won't fix your styling problem though - I'm seeing styling differences between the Pi (my target system) and my Linux Mint development system.不过,这可能无法解决您的样式问题 - 我看到 Pi(我的目标系统)和我的 Linux Mint 开发系统之间的样式差异。

I have a similar problem and running it in the following way will solve it.我有一个类似的问题,按以下方式运行它会解决它。

sudo python3.7 name.py

I guess some privilege is needed from the IDE or the current logged in user.我想 IDE 或当前登录的用户需要一些特权。 Although the colors are still more opaque than in Windows and Ubuntu.尽管颜色仍然比 Windows 和 Ubuntu 更不透明。

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

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