Qt界面美化 QSS


目前發現在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代碼   收藏代碼
  1. #include <QApplication>  
  2. #include <QPushButton>  
  3.   
  4. #include <QApplication>  
  5. #include <QFile>  
  6. #include <QStyleFactory>  
  7. #include <QTextStream>  
  8. bool setSkin(QApplication* const app, QString const &skinFile)  
  9. {  
  10.     QFile file(skinFile);  
  11.   
  12.     if (QFile::exists(skinFile) && file.open(QIODevice::ReadOnly))  
  13.     {  
  14.         QApplication::setStyle(QStyleFactory::create("Windows"));  
  15.         QString strTemp;  
  16.         QTextStream in(&file);  
  17.         while (!in.atEnd())  
  18.         {  
  19.             strTemp.append(in.readLine());  
  20.         }  
  21.         file.close();  
  22.         app->setStyleSheet(strTemp);  
  23.     }  
  24.     else  
  25.     {  
  26. #ifdef Q_WS_MAC  
  27.         qDebug("%s: %s: File does not exist %s... setting mac style...",  
  28.                __FILE__, __FUNCTION__, qPrintable(skinFile));  
  29.         app->setStyle(new QMacStyle());  
  30.         return true;  
  31. #else  
  32.         qDebug("%s: %s: File does not exist or failed to open %s",  
  33.                __FILE__, __FUNCTION__, qPrintable(skinFile));  
  34.         return false;  
  35. #endif  
  36.     }  
  37.   
  38.     return true;  
  39. }  
  40.   
  41. int main(int argc, char *argv[])  
  42. {  
  43.     //加載應用程序實例  
  44.     QApplication app(argc, argv);  
  45.   
  46.     //加載主窗口  
  47.     QWidget *widget = new QWidget();  
  48.     widget->setFixedSize(300, 300);  
  49.     widget->move(0, 0);  
  50.   
  51.     //加載PushButton  
  52.     QPushButton *button = new QPushButton("button", widget);  
  53.     button->setFixedSize(100, 100);  
  54.     button->move(100, 100);  
  55. <strong><span style="color: #800000;">  
  56.     //加載應用皮膚  
  57.     setSkin(&app ,"skin.qss");</span></strong>  
  58.   
  59.     //顯示主窗口  
  60.     widget->showNormal();  
  61.   
  62.     //循環  
  63.     return app.exec();  
  64. }  
 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM