I have the code snippet below. Basically I'm aiming to create a stacked layout with different UIs for each. I am currently creating my main window from another class. However, I noticed that when I put a background-image using stylesheets, I override the background color of my pushbutton and it only shows on the border resulting to:
In the image above: red is the color of my background and blue is the supposedly background color of my push button. I'm trying to avoid using pallettes as from the docs using it with stylesheets can result to some buggy behavior
class Main(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Main Window")
main_window = MainWindow()
width, height = 480, 720
self.setFixedSize(width, height)
# Center to the screen
qr = self.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
# Create a stack object
self.stacked_layout = QStackedLayout()
# Set central widget
self.central_widget = QWidget(self)
self.central_widget.setLayout(self.stacked_layout)
self.setCentralWidget(self.central_widget)
# Add the main window widget to the stack
self.stacked_layout.addWidget(main_window)
class MainWindow(QWidget):
def __init__(self):
super().__init__()
self.setAttribute(Qt.WA_StyledBackground)
self.setStyleSheet("background-image: url(resources/images/red_bg.jpg)")
# Create start button
self.startbtn = QPushButton("START", self)
self.startbtn.setFont(font.set_font('Roboto', 15))
self.startbtn.clicked.connect(QApplication.instance().quit)
self.startbtn.setStyleSheet("color: white; background-color:blue")
self.startbtn.installEventFilter(self)
self.startbtn.move(210, 405)