'Background doesn't load
Hi i am trying to create a GUI application for raspberry pi and pyqt5, the problem is in raspberry pi the backgrounds dose not load at all but when i run the code on my desktop it has no problem. Raspberry pi only shows a black background and not the gradient and push button backgrounds are completely ignored here is my code:
from PyQt5.QtWidgets import QMainWindow,QApplication,QPushButton
from PyQt5.QtCore import QRect
import sys
class MainWindow(QMainWindow):
def __init__(self,m_w,m_h):
super().__init__()
self.screen_sizes = (m_w,m_h)
self.window_sizes = (int(0.5*m_w),int(0.5*m_h))
self.setGeometry(int(0.25*m_w),int(0.25*m_h),int(0.5*m_w),int(0.5*m_h))
self.setFixedSize(int(0.5*m_w),int(0.5*m_h))
self.setStyleSheet(open("./css/mainwin.css").read())
toilet_dim = QRect(int(0.008*self.window_sizes[0]),int(0.072*self.window_sizes[1]),int(0.202*self.window_sizes[0]),int(0.241*self.window_sizes[1]))
self.button1(toilet_dim)
adjust_dim = QRect(int(0.008*self.window_sizes[0]),int(0.322*self.window_sizes[1]),int(0.202*self.window_sizes[0]),int(0.241*self.window_sizes[1]))
self.button2(adjust_dim)
other_dim = QRect(int(0.008*self.window_sizes[0]),int(0.570*self.window_sizes[1]),int(0.202*self.window_sizes[0]),int(0.241*self.window_sizes[1]))
self.button3(other_dim)
def button1(self,rect):
button = QPushButton(self,text="button1")
button.setStyleSheet(open("./css/pushbutton.css").read())
button.setGeometry(rect)
def button2(self,rect):
button = QPushButton(self,text="button2")
button.setStyleSheet(open("./css/pushbutton.css").read())
button.setGeometry(rect)
def button3(self,rect):
button = QPushButton(self,text="button3")
button.setStyleSheet(open("./css/pushbutton.css").read())
button.setGeometry(rect)
if __name__ == "__main__":
app = QApplication(sys.argv)
screen = app.primaryScreen()
size=screen.size()
window = MainWindow(size.width(),size.height())
window.show()
sys.exit(app.exec())
and the css code for push buttons:
QPushButton{
background-color: rgb(59, 48, 70);
color: white;
font-family: 'Rockwell';
font-weight: normal;
font-size: 18px;
}
and css code for main window:
QMainWindow{
background-color: qlineargradient(spread:pad, x1:0.573, y1:0.573545, x2:0.583, y2:0.546, stop:0.432836 rgba(46, 45, 45, 255), stop:0.442786 rgba(3, 3, 3, 255));
}
i need help for solving this problem.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
