tags:

views:

92

answers:

2

I am learning PyQt from this site. The tutorial is building a widget that colours a square.

In this, they are using CSS to colour the square, rather than give it some sort of concrete property of colour. Why is this? Is there another way to do this without CSS or is this the preferred method? It seems awfully strange..

+3  A: 

Every widget has QPalette, that can be modified and accessed via QWidget::palette() and QWidget::setPalette(p).

You can find some useful details here: QPalette in Qt 4.6. CSS is just more clean and simple (and declarative, which is SOoo popular nowadays :) ) way to determine it.

Note, that if you want only to modify your widget's background, there is a convenience method just for you: QWidget::setBackgroundRole(QPalette::ColorRole).

Max
A: 

This is one of the strengths of Qt. You can modify the UI with simple CSS. It turns out very nice if you treat correctly. Would you be interested in taking a look at my GhostQt SDK. I am using CSS for my Ghost Menu, to give it rounded corners and apply a transparent background. http://traipse.assembla.com/spaces/ghostqt (It's a side project so there is not much there)

Prof.Ebral