目前发现在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 };
#include#include #include #include #include #include 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); //加载应用皮肤 setSkin(&app ,"skin.qss"); //显示主窗口 widget->showNormal(); //循环 return app.exec(); }