[PyQt] Style sheet properties..

Jebagnana Das jebagnanadas at gmail.com
Wed Mar 10 13:51:06 GMT 2010

Thanks for your quick reply.. Have a look at this minimal example.. In the
example i've applied stylesheet only for groupbox not to any of it's
components.. Since i've set the parent as groupbox for button,label and
combo box it also reflects the style sheet properties that is applied for
group box.. In the combo box after clicking when you hover a menu item it'll
not be visible since the focus is also in white color and it doesn't look
good (esp. in linux).. In button too all it's properties are lost including
click feel(in windows).. How can i prevent this.. Please help me..

from PyQt4 import QtCore, QtGui

class Ui_Dialog(object):

    def setupUi(self, Dialog):

        Dialog.resize(399, 309)
"Dialog", None, QtGui.QApplication.UnicodeUTF8))

        self.groupBox = QtGui.QGroupBox(Dialog)
        self.groupBox.setGeometry(QtCore.QRect(10, 10, 381, 291))
        self.groupBox.setStyleSheet("background-color: rgb(255, 255,
                                    "border:1px solid rgb(255, 170, 255);")

        self.pushButton = QtGui.QPushButton(self.groupBox)
        self.pushButton.setGeometry(QtCore.QRect(110, 130, 92, 28))
"Click Me", None, QtGui.QApplication.UnicodeUTF8))

        self.label = QtGui.QLabel(self.groupBox)
        self.label.setGeometry(QtCore.QRect(50, 30, 81, 18))
        self.label.setText(QtGui.QApplication.translate("Dialog", "Name :",
None, QtGui.QApplication.UnicodeUTF8))

        self.lineEdit = QtGui.QLineEdit(self.groupBox)
        self.lineEdit.setGeometry(QtCore.QRect(140, 30, 191, 26))

        self.comboBox = QtGui.QComboBox(self.groupBox)
        self.comboBox.setGeometry(QtCore.QRect(140, 70, 85, 27))
        self.comboBox.setItemText(0, QtGui.QApplication.translate("Dialog",
"2", None, QtGui.QApplication.UnicodeUTF8))
        self.comboBox.setItemText(1, QtGui.QApplication.translate("Dialog",
"20", None, QtGui.QApplication.UnicodeUTF8))
        self.comboBox.setItemText(2, QtGui.QApplication.translate("Dialog",
"12", None, QtGui.QApplication.UnicodeUTF8))
        self.comboBox.setItemText(3, QtGui.QApplication.translate("Dialog",
"15", None, QtGui.QApplication.UnicodeUTF8))
        self.comboBox.setItemText(4, QtGui.QApplication.translate("Dialog",
"234", None, QtGui.QApplication.UnicodeUTF8))

        self.label_2 = QtGui.QLabel(self.groupBox)
        self.label_2.setGeometry(QtCore.QRect(50, 70, 81, 18))
        self.label_2.setText(QtGui.QApplication.translate("Test Dialog",
"Number :", None, QtGui.QApplication.UnicodeUTF8))


if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    Dialog = QtGui.QDialog()
    ui = Ui_Dialog()

P.S: I've used qt designer for quick designing.. Even if i hand code it the
result will be the same..

> You might take a look at so called "Selector types" (
> http://qt.nokia.com/doc/4.3/stylesheet-syntax.html#selector-types). Given
> a
> QDialog and its children (e.g. QPushButtons), this can prevent this
> cascading behaviour of styles, although I've never had any problems with
> that without using this way of "selecting" matching objects..
> Can you show a small piece of code (small stylesheet and the way you apply
> it) please?
> On Tue, Mar 9, 2010 at 9:05 PM, Jebagnana Das <jebagnanadas at gmail.com
> >wrote:
> > Hello all,
> >
> > If i apply a property to a parent widget it is automatically applied for
> > child widgets too.. Is there any way of preventing this??
> >
> > For example if i set background color as white in a dialog then any
> > button,combo boxes and scroll bars(within the dialog) looks white and it
> > lacks it's native look(have to say it's unpleasant to the eyes(esp. in
> unix)
> > & ugly).. Is there any way that i can apply the stylesheets only to a
> parent
> > widget not to it's children? can i exclude specifically some child
> widgets
> > from not inheriting parent SS properties??
> >
> > _______________________________________________
> > PyQt mailing list    PyQt at riverbankcomputing.com
> > http://www.riverbankcomputing.com/mailman/listinfo/pyqt
> >
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100310/0f4472e9/attachment.html>

More information about the PyQt mailing list