MudCatcher
MudCatcher

Reputation: 11

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. 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).

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.

Terminal output on Raspbian Buster:

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

Screenshot on Ubuntu 18.04 LTS: Screenshot of simple PyQt example program on Ubuntu 18.04 LTS

Screenshot on Raspbian Buster: Screenshot of simple PyQt example program on Raspbian Buster

Why is the red background color not displayed on 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

<?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:

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" ...

Upvotes: 1

Views: 1754

Answers (3)

Qaisar Raza
Qaisar Raza

Reputation: 1

Try using these commands:

app = QtWidgets.QApplication

app.setStyle(QStyleFactory.create('Cleanlooks'))

it will definitely work.

Upvotes: -1

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. Although the colors are still more opaque than in Windows and Ubuntu.

Upvotes: 0

David Harper
David Harper

Reputation: 89

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). 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.

Upvotes: 1

Related Questions