You are here

VTQ_PATH variable implementation

Hi Rui:
QSS stylesheets require absolute paths for images.
I have decided to add the VTQ_PATH variable to the VTQ format.

This allows you to include image backgrounds. Also extra icons for QT elements such as the arrows of the QAbstractSpinBox, QCombox, etc.

Example:
qtractorPluginListView {
background: url(VTQ_PATH/Tecnico_Images/shelves.png);
}

This greatly expands the possibilities of customizing Qtractor.
For example, currently the fader handles in my theme are made with gradients. With this implementation it is possible to create a perfectly detailed graph, with shadows, perspectives, etc.

I have implemented it and it works:

...qtractor.cpp linea 577
	// Custom style sheet (QSS)...
	if (!options.sCustomStyleSheet.isEmpty()) {
		QFile file(options.sCustomStyleSheet);
		if (file.open(QFile::ReadOnly)) {
			QFileInfo fileInfo(options.sCustomStyleSheet);
			QString vtqPath = fileInfo.path();
			QString qssContent = QString::fromUtf8(file.readAll());
			qssContent.replace("VTQ_PATH", vtqPath);
			app.setStyleSheet(qssContent);
			file.close();
		}
	}

I have a question, and it is if it would still work with accents and characters in paths from other languages.

How would you feel about adding it officially to Qtractor?

Forums: 
rncbc's picture

hi, I think having it as a special named variable or symbol is not the right thing: it would make it locked down to your VTQ offering :/

what about making all the url paths relative to the .qss file location (ie. fileInfo.absolutePath() in above code) ? and then on load, replace all url( rpath ) occurrences to final url( + fileInfo.absolutePath() + '/' + _ rpath_ ) ?

get the idea?

Yes, it is a cleaner solution.
In fact, it would work just as expected (as it does in CSS where the reference path is always the CSS file, and not the application or "index").
That also saves me from having to document it.
It just didn't occur to me that there was already a recognizable pattern for making the changes: url(

This works:

	// Custom style sheet (QSS)...
	if (!options.sCustomStyleSheet.isEmpty()) {
		QFile file(options.sCustomStyleSheet);
		if (file.open(QFile::ReadOnly)) {
			QFileInfo fileInfo(options.sCustomStyleSheet);
			QString qssPath = fileInfo.path();
			QString qssContent = QString::fromUtf8(file.readAll());
			qssContent.replace("url(", "url("+qssPath+"/");
			app.setStyleSheet(qssContent);
			file.close();
		}
	}

Example QSS:
qtractorPluginListView {
background: url(Tecnico_Images/shelves.png);
}

rncbc's picture

hi,

as proposed, the url( relative/path ) to url( /absolute/path ) substitution is now in effect (using a regular expressions): qtractor >= 1.5.2.2git.dfd7ac

please test && tell cheers

Thank you so much

Add new comment