cleanlook style for message box pyqt4

1.5k views Asked by At

I have an PYQT4 application. I try to display a lot of differnt messages based on user interaction. The problem I have is the displayed message using QMessageBox doest come up in clean look style, whereas the other part of the application works well with Clean look style.

I try to use the following code but it doenst work for the message.

# set messagebox properties
msgbox=QMessageBox()
font = QFont()
font.setFamily(_fromUtf8("Levenim MT"))
font.setPointSize(15)
msgbox.setFont(font)
msgbox.setStyle(QStyleFactory.create('Cleanlooks'))
msgbox.information(self,"Download Message", "donuts")

can someone tell me how to make this in clean look style as well

1

There are 1 answers

0
mata On BEST ANSWER

To change the style of your application, you should use QApplication.setSyle, then you have a consistent style in your whole GUI.

Setting a QWidgets's style only sets the style for the widget itself.

QWidget.setStyle:

Sets the widget's GUI style to style. The ownership of the style object is not transferred.

If no style is set, the widget uses the application's style, QApplication.style() instead.

Setting a widget's style has no effect on existing or future child widgets.

Warning: This function is particularly useful for demonstration purposes, where you want to show Qt's styling capabilities. Real applications should avoid it and use one consistent GUI style instead.

That means if you want to change the style of a widget and all it's children, you need to explicitly set it for all children by iterating through them:

cleanlooks = QStyleFactory.create('cleanlooks')
msgbox.setStyle(cleanlooks)
for child in msgbox.findChildren(QWidget):
    child.setStyle(cleanlooks)