We gonna use the form from one way.
http://techbliss.org/threads/creating-stylesheet-one-way.542/
We gonna make a stylesheet module that we import as a python module.
right click and choose style sheet
Press the pencil
then press new Resurce file.
goto your project folder and type lets say name cold.qrc
now add prefix
just let it be empty
then add files
choose any image file.
i choose something cold.
press ok and ok and check if the style sheet is valid
yep looks good
now we convert the stylesheet to python
somehow i got trouble with
pyrcc4.exe so i DL fresh copy off PyQt4.8.6 and unpacked it to a seperate folder and it works
then CMD/cd into project folder.
then
"Z:\PyQt4\pyrcc4.exe" -0 cold.py cold.qrc
make sure all are in the same folder
then edit teststule2.py and add import cold in the end off file where it says import cold_rc in the begining.
all code
regards.
http://techbliss.org/threads/creating-stylesheet-one-way.542/
We gonna make a stylesheet module that we import as a python module.
right click and choose style sheet
Press the pencil
then press new Resurce file.
goto your project folder and type lets say name cold.qrc
now add prefix
just let it be empty
then add files
choose any image file.
i choose something cold.
press ok and ok and check if the style sheet is valid
yep looks good
now we convert the stylesheet to python
somehow i got trouble with
pyrcc4.exe so i DL fresh copy off PyQt4.8.6 and unpacked it to a seperate folder and it works
then CMD/cd into project folder.
then
"Z:\PyQt4\pyrcc4.exe" -0 cold.py cold.qrc
make sure all are in the same folder
then edit teststule2.py and add import cold in the end off file where it says import cold_rc in the begining.
all code
Python:
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_topFrame(object):
def setupUi(self, topFrame):
topFrame.setObjectName(_fromUtf8("topFrame"))
topFrame.resize(938, 480)
topFrame.setStyleSheet(_fromUtf8("background-image: url(:/newPrefix/Penguins.jpg);"))
topFrame.setFrameShape(QtGui.QFrame.StyledPanel)
topFrame.setFrameShadow(QtGui.QFrame.Raised)
self.pushButton = QtGui.QPushButton(topFrame)
self.pushButton.setGeometry(QtCore.QRect(40, 20, 94, 23))
self.pushButton.setStyleSheet(_fromUtf8("QPushButton {\n"
"color: #333;\n"
"border: 2px solid #555;\n"
"border-radius: 11px;\n"
"padding: 5px;\n"
"background: qradialgradient(cx: 0.3, cy: -0.4,\n"
"fx: 0.3, fy: -0.4,\n"
"radius: 1.35, stop: 0 #fff, stop: 1 #888);\n"
"min-width: 80px;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
"background: qradialgradient(cx: 0.3, cy: -0.4,\n"
"fx: 0.3, fy: -0.4,\n"
"radius: 1.35, stop: 0 #fff, stop: 1 #bbb);\n"
"}\n"
"\n"
"QPushButton:pressed {\n"
"background: qradialgradient(cx: 0.4, cy: -0.1,\n"
"fx: 0.4, fy: -0.1,\n"
"radius: 1.35, stop: 0 #fff, stop: 1 #ddd);\n"
"}"))
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.pushButton_2 = QtGui.QPushButton(topFrame)
self.pushButton_2.setGeometry(QtCore.QRect(180, 20, 94, 23))
self.pushButton_2.setStyleSheet(_fromUtf8("QPushButton {\n"
"color: #333;\n"
"border: 2px solid #555;\n"
"border-radius: 11px;\n"
"padding: 5px;\n"
"background: qradialgradient(cx: 0.3, cy: -0.4,\n"
"fx: 0.3, fy: -0.4,\n"
"radius: 1.35, stop: 0 #fff, stop: 1 #888);\n"
"min-width: 80px;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
"background: qradialgradient(cx: 0.3, cy: -0.4,\n"
"fx: 0.3, fy: -0.4,\n"
"radius: 1.35, stop: 0 #fff, stop: 1 #bbb);\n"
"}\n"
"\n"
"QPushButton:pressed {\n"
"background: qradialgradient(cx: 0.4, cy: -0.1,\n"
"fx: 0.4, fy: -0.1,\n"
"radius: 1.35, stop: 0 #fff, stop: 1 #ddd);\n"
"}"))
self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
self.retranslateUi(topFrame)
QtCore.QMetaObject.connectSlotsByName(topFrame)
def retranslateUi(self, topFrame):
topFrame.setWindowTitle(_translate("topFrame", "Frame", None))
self.pushButton.setText(_translate("topFrame", "PushButton", None))
self.pushButton_2.setText(_translate("topFrame", "PushButton", None))
import cold
if __name__ == "__main__":
import sys
app = QtGui.QApplication.instance()
if not app:
app = QtGui.QApplication([])
topFrame = QtGui.QFrame()
ui = Ui_topFrame()
ui.setupUi(topFrame)
topFrame.show()
(app.exec_())
Last edited: