开发者

How to create a QT plugin that customizes UI?

开发者 https://www.devze.com 2023-01-29 03:10 出处:网络
We would want the users to be able to optionally customize our QT applications. So if they would want to create their own theme for our applications, all they have to do is load their own CSS file.

We would want the users to be able to optionally customize our QT applications. So if they would want to create their own theme for our applications, all they have to do is load their own CSS file.

Do we really need to create a plugin to be able to do that? If y开发者_开发问答es, could somebody give me the basic steps/ or a jump start on how to do it? If no, are there features in QT that I need to know to be able to do that without creating a plugin?


I have a Jabber instant messenger which is plugin based and written in Qt. It includes a style plugin that does exactly what you describe. The source for that plugin is here:

https://github.com/sje397/saje/tree/master/plugins/styles/

(Note: this is a plugin for my application - not a 'Qt style plugin')

Basically all you need to do is load a style sheet and call QApplication::setStyleSheet:

QFile f("filename");
if(f.open(QIODevice::ReadOnly)) {
    qApp->setStyleSheet(f.readAll());
}

An example of a valid style sheet is here. Note that it is for my app, so includes some of my own class names etc.

0

精彩评论

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

关注公众号