我有一个基于Qt的文本编辑器程序。它的默认主题是黑暗。我想添加一个特性,当用户为开关主题()选择一个QAction时,主题应该切换到光,图标也应该根据光/暗变化。在我的qrc文件中,我设置了如下结构
:/images
|--> /theme_dark/
|--> /theme_light/ 图标文件名在两个目录中都保持不变。
void MainWindow::switchTheme(const QString &themeName)
{
//themeName will be "light" or "dark"
QString image_path = ":/images/theme_"+themeName+"/";
//Now maybe we can create a QStringList and append(filenames) to it.
//Find all QActions in the toolbar and setIcon()?
}问题是暗图标在暗主题上不好看,光图标在光主题上不好看。我想知道如何有效地做到这一点。
发布于 2014-11-08 10:08:20
您可以使用QFileSelector
QFileSelector selector;
QStringList extraSelectors;
extraSelectors << "theme_dark";
selector.setExtraSelectors(extraSelectors);
QString image = selector.select(":/images/myImage.png");Qrc文件结构应该是:
:/images
|--> /+theme_dark/
|-----> myImage.png
|--> /+theme_light/
|-----> myImage.pnghttps://stackoverflow.com/questions/26815319
复制相似问题