2016-10-17 1 views
0

저는 pyqt4로 원격 앱을 만들고 있습니다. 그래서 UI에는 많은 CSS가 있습니다. 웹 앱과 같은 외부 스타일 시트를 사용하는 방법에 대해 궁금합니다. 예를 들어PyQT4 프로젝트에 외부 스타일 시트를 어떻게 사용할 수 있습니까?

: 각 위젯에 스타일 시트를 설정할 필요가

button_one.setStyleSheet("QPushButton { background-color:#444444; color:#ffffff; border: 2px solid #3d3d3d; width: 15px; height: 25px; border-radius: 15px;}" 
           "QPushButton:pressed { background-color:#ccc;}") 
Instead of the above code 
button_one.setStyleSheet("QPushButton.styleclass or #styleid") 

답변

1

없습니다.

stylesheet = """ 
QPushButton#styleid { 
    background-color: yellow; 
} 
QPushButton.styleclass { 
    background-color: magenta; 
} 
QPushButton { 
    color: blue; 
} 
""" 

QtGui.qApp.setStyleSheet(stylesheet)  

위젯의 QSS ID가 setObjectName 지정할 수 있습니다 : :이 QSS 클래스는 setProperty 지정할 수 있습니다

button_one.setObjectName('styleid') 

:

button_two.setProperty('class', 'styleclass') 
단지 전체 응용 프로그램에 대해 하나의 스타일 시트 설정

기타 qss 선택기에 대해서는 Qt 문서의 Selector Types을 참조하십시오.

0

차갑다. 당신의 대답에 대해 정말 고마워요. 내 스타일을 마침내 구분할 수있었습니다. :)

내 모든 앱 스타일을 외부 파일에 정의하고 필요한 페이지에 링크했습니다. styleFile = "styles/remote.stylesheet"open (styleFile, "r")을 fh로 사용 : self.setStyleSheet (fh.read())