开发者

Qt uses CSS to color objects? Is there another way to go about this?

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..


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).


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜