I have a Qt based text editor program. Its default theme is dark. I want to add a feature in which when the user selects a QAction for switchtheme(), the theme should toggle to light and the icons should also change according to light/dark. In my qrc file I have setup the structure as follows
:/images
|--> /theme_dark/
|--> /theme_light/
The icon file names have been kept same in both directories.
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()?
}
The thing is that dark icons don't look good on dark theme and light ones don't look good on light theme. I want to know how to do this in an efficient manner.
You can use QFileSelector:
QFileSelector selector;
QStringList extraSelectors;
extraSelectors << "theme_dark";
selector.setExtraSelectors(extraSelectors);
QString image = selector.select(":/images/myImage.png");
Qrc file structure should be:
:/images
|--> /+theme_dark/
|-----> myImage.png
|--> /+theme_light/
|-----> myImage.png
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With