2016-05-16 45 views
0

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

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

回答

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

我已经试过但它不适用于我 –

+0

我的代码对于centos很好,但它不适用于windows。 –

+0

我编辑了我的答案 –