您好,登錄后才能下訂單哦!
這篇文章主要講解了“Qt通用方法及類庫是什么”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“Qt通用方法及類庫是什么”吧!
//設置全局樣式 static void setStyle(QUIWidget::Style style); static void setStyle(const QString &qssFile, QString &paletteColor, QString &textColor); static void setStyle(const QString &qssFile, QString &textColor, QString &panelColor, QString &borderColor, QString &normalColorStart, QString &normalColorEnd, QString &darkColorStart, QString &darkColorEnd, QString &highColor); //根據QSS樣式獲取對應顏色值 static void getQssColor(const QString &qss, QString &textColor, QString &panelColor, QString &borderColor, QString &normalColorStart, QString &normalColorEnd, QString &darkColorStart, QString &darkColorEnd, QString &highColor);
void QUIHelper::setStyle(QUIWidget::Style style) { QString qssFile = ":/qss/lightblue.css"; if (style == QUIWidget::Style_Silvery) { qssFile = ":/qss/silvery.css"; } else if (style == QUIWidget::Style_Blue) { qssFile = ":/qss/blue.css"; } else if (style == QUIWidget::Style_LightBlue) { qssFile = ":/qss/lightblue.css"; } else if (style == QUIWidget::Style_DarkBlue) { qssFile = ":/qss/darkblue.css"; } else if (style == QUIWidget::Style_Gray) { qssFile = ":/qss/gray.css"; } else if (style == QUIWidget::Style_LightGray) { qssFile = ":/qss/lightgray.css"; } else if (style == QUIWidget::Style_DarkGray) { qssFile = ":/qss/darkgray.css"; } else if (style == QUIWidget::Style_Black) { qssFile = ":/qss/black.css"; } else if (style == QUIWidget::Style_LightBlack) { qssFile = ":/qss/lightblack.css"; } else if (style == QUIWidget::Style_DarkBlack) { qssFile = ":/qss/darkblack.css"; } else if (style == QUIWidget::Style_PSBlack) { qssFile = ":/qss/psblack.css"; } else if (style == QUIWidget::Style_FlatBlack) { qssFile = ":/qss/flatblack.css"; } else if (style == QUIWidget::Style_FlatWhite) { qssFile = ":/qss/flatwhite.css"; } else if (style == QUIWidget::Style_Purple) { qssFile = ":/qss/purple.css"; } else if (style == QUIWidget::Style_BlackBlue) { qssFile = ":/qss/blackblue.css"; } else if (style == QUIWidget::Style_BlackVideo) { qssFile = ":/qss/blackvideo.css"; } QFile file(qssFile); if (file.open(QFile::ReadOnly)) { QString qss = QLatin1String(file.readAll()); QString paletteColor = qss.mid(20, 7); getQssColor(qss, QUIConfig::TextColor, QUIConfig::PanelColor, QUIConfig::BorderColor, QUIConfig::NormalColorStart, QUIConfig::NormalColorEnd, QUIConfig::DarkColorStart, QUIConfig::DarkColorEnd, QUIConfig::HighColor); qApp->setPalette(QPalette(QColor(paletteColor))); qApp->setStyleSheet(qss); file.close(); } } void QUIHelper::setStyle(const QString &qssFile, QString &paletteColor, QString &textColor) { QFile file(qssFile); if (file.open(QFile::ReadOnly)) { QString qss = QLatin1String(file.readAll()); paletteColor = qss.mid(20, 7); textColor = qss.mid(49, 7); getQssColor(qss, QUIConfig::TextColor, QUIConfig::PanelColor, QUIConfig::BorderColor, QUIConfig::NormalColorStart, QUIConfig::NormalColorEnd, QUIConfig::DarkColorStart, QUIConfig::DarkColorEnd, QUIConfig::HighColor); qApp->setPalette(QPalette(QColor(paletteColor))); qApp->setStyleSheet(qss); file.close(); } } void QUIHelper::setStyle(const QString &qssFile, QString &textColor, QString &panelColor, QString &borderColor, QString &normalColorStart, QString &normalColorEnd, QString &darkColorStart, QString &darkColorEnd, QString &highColor) { QFile file(qssFile); if (file.open(QFile::ReadOnly)) { QString qss = QLatin1String(file.readAll()); getQssColor(qss, textColor, panelColor, borderColor, normalColorStart, normalColorEnd, darkColorStart, darkColorEnd, highColor); qApp->setPalette(QPalette(QColor(panelColor))); qApp->setStyleSheet(qss); file.close(); } } void QUIHelper::getQssColor(const QString &qss, QString &textColor, QString &panelColor, QString &borderColor, QString &normalColorStart, QString &normalColorEnd, QString &darkColorStart, QString &darkColorEnd, QString &highColor) { QString str = qss; QString flagTextColor = "TextColor:"; int indexTextColor = str.indexOf(flagTextColor); if (indexTextColor >= 0) { textColor = str.mid(indexTextColor + flagTextColor.length(), 7); } QString flagPanelColor = "PanelColor:"; int indexPanelColor = str.indexOf(flagPanelColor); if (indexPanelColor >= 0) { panelColor = str.mid(indexPanelColor + flagPanelColor.length(), 7); } QString flagBorderColor = "BorderColor:"; int indexBorderColor = str.indexOf(flagBorderColor); if (indexBorderColor >= 0) { borderColor = str.mid(indexBorderColor + flagBorderColor.length(), 7); } QString flagNormalColorStart = "NormalColorStart:"; int indexNormalColorStart = str.indexOf(flagNormalColorStart); if (indexNormalColorStart >= 0) { normalColorStart = str.mid(indexNormalColorStart + flagNormalColorStart.length(), 7); } QString flagNormalColorEnd = "NormalColorEnd:"; int indexNormalColorEnd = str.indexOf(flagNormalColorEnd); if (indexNormalColorEnd >= 0) { normalColorEnd = str.mid(indexNormalColorEnd + flagNormalColorEnd.length(), 7); } QString flagDarkColorStart = "DarkColorStart:"; int indexDarkColorStart = str.indexOf(flagDarkColorStart); if (indexDarkColorStart >= 0) { darkColorStart = str.mid(indexDarkColorStart + flagDarkColorStart.length(), 7); } QString flagDarkColorEnd = "DarkColorEnd:"; int indexDarkColorEnd = str.indexOf(flagDarkColorEnd); if (indexDarkColorEnd >= 0) { darkColorEnd = str.mid(indexDarkColorEnd + flagDarkColorEnd.length(), 7); } QString flagHighColor = "HighColor:"; int indexHighColor = str.indexOf(flagHighColor); if (indexHighColor >= 0) { highColor = str.mid(indexHighColor + flagHighColor.length(), 7); } }
感謝各位的閱讀,以上就是“Qt通用方法及類庫是什么”的內容了,經過本文的學習后,相信大家對Qt通用方法及類庫是什么這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。