簡體   English   中英

PyQt5 StackedWidget第一頁邊框圖像不起作用

[英]PyQt5 StackedWidget the first page border image does not work

我正在使用帶有PyQt5的堆疊式小部件來實現菜單頁面和子菜單頁面,並且我試圖設置一個歡迎頁面,一旦您運行該應用程序並在3秒鍾后切換到主菜單頁面,該頁面就會顯示。 我遇到的問題是,當我將.ui文件轉換為.py文件並執行腳本時,除歡迎頁面邊框圖像(未顯示)之外,所有頁面邊框圖像都工作正常。

請注意,我正在使用Qt Designer

這是錯誤...這是歡迎頁面未顯示邊框圖像: 在此處輸入圖片說明

其他頁面工作正常,其他頁面(顯示其邊框圖像): 在此處輸入圖片說明 謝謝

代碼:

 # -*- 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_())

我嘗試了您的代碼,它對我有用。

您應檢查的內容:

  • 文件路徑是否正確:/img/img/main menu.png
  • 嘗試將映像放在磁盤上,然后重試
  • 嘗試使用簡單的名稱(例如D:/im.png將映像放在磁盤上
  • 嘗試使用已在另一頁面上使用的圖像
  • 檢查您的資源文件是否已編譯(您可以在Qt Creator的編譯器日志中找到對rcc.exe的調用)。

從Qt的角度來看,它看起來不錯。

真是令人困惑,但它正在工作! 我剛剛再次轉換了.qrc文件,它現在運行良好

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM