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

时间:2016-05-16 04:57:50

标签: python pyqt4 qgis

这个问题可能重复,但我不能解决我的问题 我正在使用python 2.7 无法使用python设置Qframe的背景图像以下代码在centos中工作正常但在窗口7中甚至没有显示任何错误,

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 ""

1 个答案:

答案 0 :(得分:0)

此代码适用于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 ""