[英]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. 我正在使用带有PyQt5的堆叠式小部件来实现菜单页面和子菜单页面,并且我试图设置一个欢迎页面,一旦您运行该应用程序并在3秒钟后切换到主菜单页面,该页面就会显示。 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 ) . 我遇到的问题是,当我将.ui文件转换为.py文件并执行脚本时,除欢迎页面边框图像(未显示)之外,所有页面边框图像都工作正常。
Note that i'm using Qt Designer 请注意,我正在使用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: 您应检查的内容:
:/img/img/main menu.png
? 文件路径是否正确:/img/img/main menu.png
? D:/im.png
尝试使用简单的名称(例如D:/im.png
将映像放在磁盘上 rcc.exe
in the compiler log in Qt Creator). 检查您的资源文件是否已编译(您可以在Qt Creator的编译器日志中找到对rcc.exe
的调用)。 From the Qt side of things it looks good. 从Qt的角度来看,它看起来不错。
that's pretty confusing but it's working !! 真是令人困惑,但它正在工作! i just converted .qrc file again again and it's working well now 我刚刚再次转换了.qrc文件,它现在运行良好
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.