目前發現在Qt-Design中右擊控件,可以選擇Change StyleSheet
------------------------以下總結不太對
剛接觸Qt,發現Qt Design無法對每個控件進行顏色風格設置。正在納悶如此受歡迎的開發工具,怎么會沒有這種,Delphi,VB,VC,C#都具備的基本功能呢?
后來在CSDN上才知道,Qt已經走在這些工具的最前方了,把界面已經獨立出來和web編程一樣。web有CSS專門美化工作。而Qt也有QSS進行美化設計。完全可以不影響程序開發。而且可以直接調用網上經典的界面代碼。
Qt思想確實是先進不少啊。
目前沒有精力研究Qt美化界面的問題。先了解一下放在這兒。
一些QSS的例子
skin.qss中,寫上QPushButton { color: red };
- #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();
- }

