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

Python Raspbian上的PyQt5:不显示QWidgets的背景色,python,pyqt,pyqt5,raspbian,qtstylesheets,Python,Pyqt,Pyqt5,Raspbian,Qtstylesheets,我已经在一个运行Raspbian Buster的Raspberry Pi 3B+上编译并安装了PyQt5,如前所述。虽然花了几个小时,但还是奏效了。之后,我上传了由2个文件组成的简单PyQt示例程序(main.py和mainwindow.ui) 为QProgressBar和QPushButton设置的红色背景色在运行Ubuntu18.04 LTS的我的电脑上以不同的红色(?)显示,但在Raspberry Pi上根本不显示 Raspbian Buster上的终端输出: libEGL warning

我已经在一个运行Raspbian Buster的Raspberry Pi 3B+上编译并安装了PyQt5,如前所述。虽然花了几个小时,但还是奏效了。之后,我上传了由2个文件组成的简单PyQt示例程序(
main.py
mainwindow.ui

QProgressBar
QPushButton
设置的红色背景色在运行Ubuntu18.04 LTS的我的电脑上以不同的红色(?)显示,但在Raspberry Pi上根本不显示

Raspbian Buster上的终端输出:

libEGL warning: DRI2: failed to authenticate
qt5ct: using qt5ct plugin
qt5ct: D-Bus global menu: no
Ubuntu 18.04 LTS上的屏幕截图:

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()
main window.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>

我今天也遇到了类似的问题(我就是这样找到你的帖子的)。要消除libEGL警告,请运行raspi config并从高级选项->GL驱动程序(然后重新启动)中选择“完整公里数”选项。不过,这可能不会解决您的样式问题-我看到了Pi(我的目标系统)和Linux Mint开发系统之间的样式差异。

我有一个类似的问题,用以下方式运行它可以解决它

sudo python3.7 name.py
我想IDE或当前登录用户需要一些特权。
尽管颜色仍然比Windows和Ubuntu更不透明。

当您从终端运行文件时,是否会收到错误消息?在您的raspbian和ubuntu中,
print(app.style().metaObject().className())
的输出是什么?ubuntu上没有终端输出,但在raspbian上显示以下内容libEGL警告:DRI2:验证qt5ct失败:使用qt5ct插件qt5ct:D-Bus全局菜单:否`` Python命令既不会在Ubuntu上也不会在Raspbian上产生输出。导出QT_调试_插件=1的输出是什么设置
export QT\u DEBUG\u PLUGINS=1后
sudo python3.7 name.py