如何在QtC++中更改基于主题的图标?如果可用的主题是深色或浅色
How to change icons based on theme in Qt C++? If available themes are dark or light
我有一个基于Qt的文本编辑器程序。它的默认主题是深色。我想添加一个功能,当用户为switchtheme()选择一个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()?
}
问题是深色图标在深色主题上看起来不好,浅色图标在浅色主题上看起来也不好。我想知道如何以有效的方式做到这一点。
您可以使用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.png
相关文章:
- 如果没有malloc,链表实现将失败
- 如果我只是不访问queue_front节点的子节点,而是将它们推到队列中呢?还是BFS吗
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 获取日期异步信号安全吗?如果在信号处理程序中使用,它会导致死锁吗
- 设计一个只能由特定类实例化的类(如果可能的话,通过make_unique)
- 线程,如果else语句,都是错误的上下文切换后,会发生什么
- 如果编译的源代码是特定于它编译的硬件的,我们如何分发它
- 如果我std::dynamic_pointer_cast并且底层dynamic_cast的结果为null,那么返回的sh
- C++擦除(如果存在)
- 如果"new int"返回"int*",那么为什么"new int[n]"不返回"int**"?
- 在'如果'陈述输出如何正确
- 如果用户输入无效,如何使用字符串变量-C++重复输入命令
- 如果有一个模板构造函数只有一个泛型参数,为什么我必须有一个复制构造函数
- 如果基类包含双指针成员,则派生类的构造函数
- 如果没有数学库,我如何在C++中创建复利公式
- 如果我已经有一个头,那么模板(-t)文件属于哪里
- 如果C++对象的类在另一个boost模块中声明,如何使用boost将指向该对象的指针返回到python
- 如果条件为TRUE(最佳方式?),则在do while循环中后置增量
- 如何在QtC++中更改基于主题的图标?如果可用的主题是深色或浅色