简体   繁体   中英

PyQt5 StackedWidget the first page border image does not work

I'm using stacked widget with PyQt5 to realize a menu page and sub menu pages and i'm trying to set a welcome page that is shown once u run the application and switched to main menu page after 3 seconds. the problem that i encoutered is that when i convert the .ui file to .py file and execute the script, all pages border images are working fine except the welcome page border image ( it is not shown ) .

Note that i'm using Qt Designer

here is the error ... this is the welcome page does not show the border image : 在此处输入图片说明

and the other pages are working fine this one the other pages ( it shows its border image ) : 在此处输入图片说明 thank you

code :

 # -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'G:\Users\Mohamed.Souilem\Projects\Smart Updater - BLT SLT\smart updater UI\smartupdater.ui'
#
# Created by: PyQt5 UI code generator 5.11.2
#
# WARNING! All changes made in this file will be lost!

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_smartUpdaterUI(object):
    def setupUi(self, smartUpdaterUI):
        smartUpdaterUI.setObjectName("smartUpdaterUI")
        smartUpdaterUI.resize(667, 357)
        smartUpdaterUI.setMinimumSize(QtCore.QSize(667, 357))
        smartUpdaterUI.setMaximumSize(QtCore.QSize(667, 16777215))
        font = QtGui.QFont()
        font.setFamily("Ubuntu Mono")
        smartUpdaterUI.setFont(font)
        smartUpdaterUI.setToolTipDuration(0)
        smartUpdaterUI.setAutoFillBackground(True)
        smartUpdaterUI.setStyleSheet("color:white")
        smartUpdaterUI.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)
        smartUpdaterUI.setTabShape(QtWidgets.QTabWidget.Triangular)
        self.Main_menu = QtWidgets.QWidget(smartUpdaterUI)
        self.Main_menu.setStyleSheet("border-image: url(:/img/img/main menu.png);")
        self.Main_menu.setObjectName("Main_menu")
        self.deviceInfo_Button = QtWidgets.QPushButton(self.Main_menu)
        self.deviceInfo_Button.setGeometry(QtCore.QRect(56, 44, 123, 119))
        self.deviceInfo_Button.setStyleSheet("border-image: url(:/img/img/info_button.png);")
        self.deviceInfo_Button.setText("")
        self.deviceInfo_Button.setObjectName("deviceInfo_Button")
        self.wifi_Button = QtWidgets.QPushButton(self.Main_menu)
        self.wifi_Button.setGeometry(QtCore.QRect(270, 44, 123, 119))
        self.wifi_Button.setStyleSheet("border-image: url(:/img/img/wifi_button.png);")
        self.wifi_Button.setText("")
        self.wifi_Button.setObjectName("wifi_Button")
        self.lan_Button = QtWidgets.QPushButton(self.Main_menu)
        self.lan_Button.setGeometry(QtCore.QRect(470, 44, 125, 119))
        self.lan_Button.setStyleSheet("border-image: url(:/img/img/lan_button.png);")
        self.lan_Button.setText("")
        self.lan_Button.setObjectName("lan_Button")
        self.power_Button = QtWidgets.QPushButton(self.Main_menu)
        self.power_Button.setGeometry(QtCore.QRect(56, 200, 123, 119))
        self.power_Button.setStyleSheet("border-image: url(:/img/img/power_button.png);")
        self.power_Button.setText("")
        self.power_Button.setObjectName("power_Button")
        self.user_Button = QtWidgets.QPushButton(self.Main_menu)
        self.user_Button.setGeometry(QtCore.QRect(270, 200, 123, 119))
        self.user_Button.setStyleSheet("border-image: url(:/img/img/user_button.png);")
        self.user_Button.setText("")
        self.user_Button.setObjectName("user_Button")
        self.test_Button = QtWidgets.QPushButton(self.Main_menu)
        self.test_Button.setGeometry(QtCore.QRect(470, 200, 125, 119))
        self.test_Button.setStyleSheet("border-image: url(:/img/img/test_button.png);")
        self.test_Button.setText("")
        self.test_Button.setObjectName("test_Button")
        self.deviceInfo_text = QtWidgets.QLabel(self.Main_menu)
        self.deviceInfo_text.setGeometry(QtCore.QRect(70, 170, 95, 20))
        font = QtGui.QFont()
        font.setFamily("Segoe UI Semibold")
        font.setPointSize(12)
        font.setBold(True)
        font.setWeight(75)
        self.deviceInfo_text.setFont(font)
        self.deviceInfo_text.setStyleSheet("color:white ")
        self.deviceInfo_text.setObjectName("deviceInfo_text")
        self.wirelessConnection_text = QtWidgets.QLabel(self.Main_menu)
        self.wirelessConnection_text.setGeometry(QtCore.QRect(296, 170, 75, 20))
        font = QtGui.QFont()
        font.setFamily("Segoe UI Semibold")
        font.setPointSize(12)
        font.setBold(True)
        font.setWeight(75)
        self.wirelessConnection_text.setFont(font)
        self.wirelessConnection_text.setAutoFillBackground(False)
        self.wirelessConnection_text.setStyleSheet("color:white ")
        self.wirelessConnection_text.setObjectName("wirelessConnection_text")
        self.lanConnection_text = QtWidgets.QLabel(self.Main_menu)
        self.lanConnection_text.setGeometry(QtCore.QRect(520, 170, 31, 20))
        font = QtGui.QFont()
        font.setFamily("Segoe UI Semibold")
        font.setPointSize(12)
        font.setBold(True)
        font.setWeight(75)
        self.lanConnection_text.setFont(font)
        self.lanConnection_text.setStyleSheet("color:white ")
        self.lanConnection_text.setObjectName("lanConnection_text")
        self.powerOFF_text = QtWidgets.QLabel(self.Main_menu)
        self.powerOFF_text.setGeometry(QtCore.QRect(76, 328, 87, 20))
        font = QtGui.QFont()
        font.setFamily("Segoe UI Semibold")
        font.setPointSize(12)
        font.setBold(True)
        font.setWeight(75)
        self.powerOFF_text.setFont(font)
        self.powerOFF_text.setStyleSheet("color:white ")
        self.powerOFF_text.setObjectName("powerOFF_text")
        self.user_text = QtWidgets.QLabel(self.Main_menu)
        self.user_text.setGeometry(QtCore.QRect(316, 328, 41, 20))
        font = QtGui.QFont()
        font.setFamily("Segoe UI Semibold")
        font.setPointSize(12)
        font.setBold(True)
        font.setWeight(75)
        self.user_text.setFont(font)
        self.user_text.setStyleSheet("color:white ")
        self.user_text.setObjectName("user_text")
        self.test_text = QtWidgets.QLabel(self.Main_menu)
        self.test_text.setGeometry(QtCore.QRect(476, 328, 117, 20))
        font = QtGui.QFont()
        font.setFamily("Segoe UI Semibold")
        font.setPointSize(12)
        font.setBold(True)
        font.setWeight(75)
        self.test_text.setFont(font)
        self.test_text.setStyleSheet("color:white ")
        self.test_text.setObjectName("test_text")
        self.menu_text = QtWidgets.QLabel(self.Main_menu)
        self.menu_text.setGeometry(QtCore.QRect(6, 6, 73, 19))
        font = QtGui.QFont()
        font.setFamily("MS Reference Sans Serif")
        font.setPointSize(17)
        font.setBold(True)
        font.setWeight(75)
        self.menu_text.setFont(font)
        self.menu_text.setObjectName("menu_text")
        smartUpdaterUI.setCentralWidget(self.Main_menu)

        self.retranslateUi(smartUpdaterUI)
        QtCore.QMetaObject.connectSlotsByName(smartUpdaterUI)

    def retranslateUi(self, smartUpdaterUI):
        _translate = QtCore.QCoreApplication.translate
        smartUpdaterUI.setWindowTitle(_translate("smartUpdaterUI", "Yamaichi Electronics Smart Updater "))
        self.deviceInfo_text.setText(_translate("smartUpdaterUI", "DEVICE INFO"))
        self.wirelessConnection_text.setText(_translate("smartUpdaterUI", "WIRELESS "))
        self.lanConnection_text.setText(_translate("smartUpdaterUI", "LAN"))
        self.powerOFF_text.setText(_translate("smartUpdaterUI", "POWER OFF"))
        self.user_text.setText(_translate("smartUpdaterUI", "USER"))
        self.test_text.setText(_translate("smartUpdaterUI", "TESTING MODE"))
        self.menu_text.setText(_translate("smartUpdaterUI", "Menu"))

import resource_rc

if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    smartUpdaterUI = QtWidgets.QMainWindow()
    ui = Ui_smartUpdaterUI()
    ui.setupUi(smartUpdaterUI)
    smartUpdaterUI.show()
    sys.exit(app.exec_())

I tried your code and it worked for me.

What you should check:

  • Is the file path correct :/img/img/main menu.png ?
  • Try to put the image on your disk and retry
  • Try to put the image on your disk with a simple name like D:/im.png
  • Try to use an image that is already working for another page
  • Check that your ressource file is compiled (you can find a call to rcc.exe in the compiler log in Qt Creator).

From the Qt side of things it looks good.

that's pretty confusing but it's working !! i just converted .qrc file again again and it's working well now

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM