Reputation: 33
I created a file using QT Designer, and I uploaded a background image. This file works well and the image appears in the background. However, when the file is import to the main file, the image does not appear in the background correctly.
and project link https://github.com/ahmedlam3y/GarageSystem
Upvotes: 1
Views: 2231
Reputation: 33
Because it is not the main window, but it is ًWidget so the picture was not visible in the background and one of the Widgets has been set to the mainWindow so it work correctly and The code for solution:
import sys
from PyQt5.QtCore import QSize
from PyQt5 import QtCore, QtGui, QtWidgets as Q
from PyQt5.QtGui import QImage, QPalette, QBrush
from PyQt5.QtWidgets import *
import image_rc
from SignIN import Ui_Form as SignInForm
from WelFrame import Ui_Form as WelFrameForm
from SignUp import Ui_Form as SignUpForm
from Accounting import Ui_Form as AccountForm
class SignIn(Q.QWidget, SignInForm): # Widget
def __init__(self, parent=None):
super(SignIn, self).__init__(parent)
Q.QWidget.__init__(self, parent)
self.setupUi(self)
oImage = QImage("GTR.png")
sImage = oImage.scaled(QSize(600, 360)) # resize Image to widgets size
palette = QPalette()
palette.setBrush(10, QBrush(sImage)) # 10 = WindowRole
self.setPalette(palette)
class WelFrame(Q.QMainWindow, WelFrameForm): # MainWindow
def __init__(self, parent=None):
Q.QWidget.__init__(self, parent)
self.setupUi(self)
class SignUp(Q.QWidget, SignUpForm): # Widget
def __init__(self, parent=None):
Q.QWidget.__init__(self, parent)
self.setupUi(self)
oImage = QImage("GTR.png")
sImage = oImage.scaled(QSize(600, 360)) # resize Image to widgets size
palette = QPalette()
palette.setBrush(10, QBrush(sImage)) # 10 = WindowRole
self.setPalette(palette)
class Accout(Q.QWidget, AccountForm): # Widget
def __init__(self, parent=None):
Q.QWidget.__init__(self, parent)
self.setupUi(self)
oImage = QImage("GTR.png")
sImage = oImage.scaled(QSize(600, 360)) # resize Image to widgets size
palette = QPalette()
palette.setBrush(10, QBrush(sImage)) # 10 = WindowRole
self.setPalette(palette)
def foo(w1, w2):
w1.show()
w2.hide()
if __name__ == '__main__':
app = Q.QApplication(sys.argv)
wel = WelFrame()
signIn = SignIn()
signUp = SignUp()
accout = AccountForm()
wel.pushButton_2.clicked.connect(lambda: foo(signIn, wel))
wel.pushButton.clicked.connect(lambda: foo(signUp, wel))
signIn.pushButton_2.clicked.connect(lambda: foo(wel, signIn))
signUp.pushButton_2.clicked.connect(lambda: foo(wel, signUp))
wel.show()
sys.exit(app.exec_())
Upvotes: 1