Git Product home page Git Product logo

libqss's Introduction

A simple Qt CSS (QSS) dialect parser

The parser is written in C++14 and parses the supported dialect of QSS i.e. Qt's CSS system. This is not exactly the same as CSS3 (web standards) which is a superset of QSS. As Qt Widgets library does not expose the built-in parser, this library takes care of parsing.

Note: This library does not actually update widgets when properties are modified. This can however be done by writing appropriate wrappers on top of Qt widget classes.

Building

mkdir build
cd build
cmake ..
make

Testing

cd build
./test_qss

Example

Parse QDarkStyleSheet and extract background color of QWidget:

QApplication a(argc, argv);
...
QString styleSheetLocation = QString(":qdarkstyle/dark/style.qss");
QFile styleSheetFile(styleSheetLocation);

if (!styleSheetFile.exists())
	printf("Unable to set stylesheet, file not found\n");
else
{
	QTextStream ts(&styleSheetFile);
	styleSheetFile.open(QFile::ReadOnly | QFile::Text);
	a.setStyleSheet(ts.readAll());
}
...
qss::Document document(qApp->styleSheet());
for (auto it = document.cbegin(); it < document.cend(); it++)
{
	auto fragment = it->first;
	if (fragment.selector().toString() != "QWidget") continue;
	
	auto block = fragment.block();
	for (auto it2 = block.cbegin(); it2 != block.cend(); it2++)
	{
		auto name = it2->first;
		if (name != "background-color") continue;
		
		auto value = it2->second.first;
		qDebug() << value << "\n";
		return value;
	}
}

libqss's People

Contributors

ajax-crypto avatar akash-pradhan avatar dmikushin avatar ncirit avatar

Watchers

 avatar

Forkers

ncirit

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.