explicitly setting style sheet in python pyqt4?
<p>In pyqt standard way for setting style sheet is like this <br><br>
<code>MainWindow.setStyleSheet(_fromUtf8("/*\n"
"gridline-color: rgb(85, 170, 255);\n"
"QToolTip\n"
"{\n"
"    border: 1px solid #76797C;\n"
"    background-color: rgb(90, 102, 117);;\n"
"    color: white;\n"
"    padding: 5px;\n"
"    opacity: 200;\n"
"}\n"
"#label_3{\n"
"    background-color:rgb(90, 102, 117);\n"
"    color:white;\n"
"    padding-left:20px;\n"
" \n"
"}\n"
"#label_2{\n"
"    color:white;\n"
"    padding-left:20px;\n"
" \n"
"}\n"</code></p>

<p>But like we link the stylesheet in html
<code>&lt;link rel="stylesheet" href="style.css"&gt;</code>
.can't we do the same in pyqt?It helps in organizing the things.</p>

<p>There are currently only two main ways to set a stylesheet. The first is to use the <code>setStyleSheet</code> method:</p>

<pre><code>widget.setStyleSheet("""
    QToolTip {
        border: 1px solid #76797C;
        background-color: rgb(90, 102, 117);
        color: white;
        padding: 5px;
        opacity: 200;
    }
    """)
</code></pre>

<p>This will only take a string, so an external resource would need to be explicitly read from a file, or imported from a module.</p>

<p>The second method is to use the <a href="http://doc.qt.io/qt-4.8/qapplication.html#QApplication" rel="nofollow"><code>-stylesheet</code> command-line argument</a>, which allows an external qss resource to be specified as a path:</p>

<pre><code>python myapp.py -stylesheet style.qss
</code></pre>

<p>This opens up the possibility of a tempting hack, since it is easy enough to manipulate the args passed to the <code>QApplication</code> constructor, and explicitly insert a default stylesheet:</p>

<pre><code>import sys

args = list(sys.argv)
args[1:1] = ['-stylesheet', 'style.qss']

app = QtGui.QApplication(args)
</code></pre>

<p>(Inserting the extra arguments at the beginning of the list ensures that it is still possible for the user to override the default with their own stylesheet).</p>

python pyqt pyqt4 qss