您的位置:首页 > 编程语言 > Qt开发

Qt界面美化 QSS

2013-06-12 23:10 447 查看
目前发现在Qt-Design中右击控件,可以选择Change StyleSheet

------------------------以下总结不太对

刚接触Qt,发现Qt Design无法对每个控件进行颜色风格设置。正在纳闷如此受欢迎的开发工具,怎么会没有这种,Delphi,VB,VC,C#都具备的基本功能呢?

后来在CSDN上才知道,Qt已经走在这些工具的最前方了,把界面已经独立出来和web编程一样。web有CSS专门美化工作。而Qt也有QSS进行美化设计。完全可以不影响程序开发。而且可以直接调用网上经典的界面代码。

Qt思想确实是先进不少啊。

目前没有精力研究Qt美化界面的问题。先了解一下放在这儿。

一些QSS的例子

QT皮肤(QSS)编程

qt样式qss应用

QT皮肤(QSS)编程

skin.qss中,写上QPushButton { color: red };

Cpp代码


#include <QApplication>

#include <QPushButton>

#include <QApplication>

#include <QFile>

#include <QStyleFactory>

#include <QTextStream>

bool setSkin(QApplication* const app, QString const &skinFile)

{

QFile file(skinFile);

if (QFile::exists(skinFile) && file.open(QIODevice::ReadOnly))

{

QApplication::setStyle(QStyleFactory::create("Windows"));

QString strTemp;

QTextStream in(&file);

while (!in.atEnd())

{

strTemp.append(in.readLine());

}

file.close();

app->setStyleSheet(strTemp);

}

else

{

#ifdef Q_WS_MAC

qDebug("%s: %s: File does not exist %s... setting mac style...",

__FILE__, __FUNCTION__, qPrintable(skinFile));

app->setStyle(new QMacStyle());

return true;

#else

qDebug("%s: %s: File does not exist or failed to open %s",

__FILE__, __FUNCTION__, qPrintable(skinFile));

return false;

#endif

}

return true;

}

int main(int argc, char *argv[])

{

//加载应用程序实例

QApplication app(argc, argv);

//加载主窗口

QWidget *widget = new QWidget();

widget->setFixedSize(300, 300);

widget->move(0, 0);

//加载PushButton

QPushButton *button = new QPushButton("button", widget);

button->setFixedSize(100, 100);

button->move(100, 100);

<strong><span style="color: #800000;">

//加载应用皮肤

setSkin(&app ,"skin.qss");</span></strong>

//显示主窗口

widget->showNormal();

//循环

return app.exec();

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: