无法使用python设置Qframe的背景图像

2024-10-03 06:20:46 发布

您现在位置:Python中文网/ 问答频道 /正文

这个问题可能会重复,但我的问题得不到答案 我使用的是python2.7 无法使用python设置Qframe的背景图像,下面的代码在centos中可以正常工作,但是在windows7中甚至没有显示任何错误

self.frame_2.setStyleSheet(_fromUtf8("border:0px;background-image:   
url("+self.getImagePath("4.jpg")+")"))

 def getImagePath(self,image):

    pluginPath = (os.path.dirname(__file__))
    themePath = str("icons")  + QDir.separator() + str(image)
    filePath =  pluginPath + QDir.separator() + themePath
    if QFile.exists(pluginPath + QDir.separator() + themePath):

         return filePath
    else:
        return ""

Tags: 答案代码图像imageselfreturn背景str
1条回答
网友
1楼 · 发布于 2024-10-03 06:20:46

这段代码在windows上运行。在

import re

self.frame_2.setStyleSheet(_fromUtf8("border:0px;background-image:   
url("+self.getImagePath("4.jpg")+")"))

def getImagePath(self,image):
    pluginPath = (os.path.dirname(__file__))
    themePath = str("images")  + QDir.separator() + str(image)
    filePath =  pluginPath + QDir.separator() + themePath
    if QFile.exists(os.path.normpath(filePath)):
         return re.sub("\\\\","//",(os.path.normpath(filePath)))
    else:
        return ""

相关问题 更多 >