样式表元素在Windows中可以使用,但在树莓派中不能使用。

问题描述 投票:0回答:1

我在Windows 10机器上写了一个程序,并将代码通过SSH传入到运行Raspbian的Raspberry Pi机器上。当把一些样式表应用到某些对象上时,它们在Windows上看起来很好,但某些元素在Linux机器上却没有被接收到。

我创建了一个测试程序来显示发生了什么。

This is on the Windows machine, all is working as expected

This is on the Raspbian machine

我在Raspbian机器上遇到的唯一问题就是背景没有被填充。字体大小和颜色的属性都能正常显示。我试着用 .autoFillBackground().setAttribute(Qt.WA_StyledBackground) 但都没有得到任何结果。

我也试过结合使用 QPushButton::active:background:background-color: 没有任何运气。

有什么想法吗?

EDIT:PySide2是使用安装。

apt-get install python3-pyside2.qt3dcore python3-pyside2.qt3dinput python3-pyside2.qt3dlogic python3-pyside2.qt3drender python3-pyside2.qtcharts python3-pyside2.qtconcurrent python3-pyside2.qtcore python3-pyside2.qtgui python3-pyside2.qthelp python3-pyside2.qtlocation python3-pyside2.qtmultimedia python3-pyside2.qtmultimediawidgets python3-pyside2.qtnetwork python3-pyside2.qtopengl python3-pyside2.qtpositioning python3-pyside2.qtprintsupport python3-pyside2.qtqml python3-pyside2.qtquick python3-pyside2.qtquickwidgets python3-pyside2.qtscript python3-pyside2.qtscripttools python3-pyside2.qtsensors python3-pyside2.qtsql python3-pyside2.qtsvg python3-pyside2.qttest python3-pyside2.qttexttospeech python3-pyside2.qtuitools python3-pyside2.qtwebchannel python3-pyside2.qtwebsockets python3-pyside2.qtwidgets python3-pyside2.qtx11extras python3-pyside2.qtxml python3-pyside2.qtxmlpatterns python3-pyside2uic

从... https:/forum.qt.iotopic112813在raspberry-pi上安装pyside2。

import sys

from PySide2.QtWidgets import *
from PySide2.QtGui import *
from PySide2.QtCore import *


class Window(QWidget):
    def __init__(self):
        QWidget.__init__(self)

        self.btn1 = QPushButton("Button 1")
        self.btn2 = QPushButton("Button 2")

        self.btn1.setStyleSheet("""background: blue; color: yellow; border: 3px solid black""")
        self.btn2.setStyleSheet("background: red; color: white; font-size: 30px;")

        layout = QVBoxLayout()
        layout.addWidget(self.btn1)
        layout.addWidget(self.btn2)

        self.setLayout(layout)


app = QApplication(sys.argv)
window = Window()
window.show()
app.exec_()
python python-3.x raspberry-pi pyside2 qtstylesheets
1个回答
0
投票

呜好吧,所以轻微的发展。我发现,如果你添加一个边框,颜色就会被填充。有点奇怪,但我想这是可行的。它并不理想,因为这样做按钮会失去 "按下 "的状态,但我会把它弄乱,看看我得到了什么。

"border: none; "也会填充背景。

Border needed

© www.soinside.com 2019 - 2024. All rights reserved.