1

Hy,

i m working on a qt application styled by a stylesheet, set like

   QApplication qApplication(argc, argv);

   QFile styleFile("myStyleFile.stylesheet");
   bool check = styleFile.open(QFile::ReadOnly);
   qApplication.setStyleSheet(styleFile.readAll());

the important window of this application uses a QGraphicsScene (which items are not styleable with stylesheets). But i wannt a unique look.

So the questions are:

1.) Is there a way to access the set stylesheet properties ( like getProperty("QMenu::item:selected") )?

2.) or does anyone know a css-syntax to xml-file tool? (than one could access the set properties with the qt xml/dom support)

I know that some special properties can be accessed like

   QColor mainWindowbackgroundColor = 
       palette().color( QWidget::backgroundRole() );//Get the backgroundcolor set by stylesheet.

but i am searching for a way to access ALL set properties.

Thank you!

Blazemonger
  • 90,923
  • 26
  • 142
  • 180
user1911091
  • 1,219
  • 2
  • 14
  • 32

1 Answers1

4

I think you will need to use private Qt classes to do this. This is generally not a good idea as the interfaces are internal and subject to change.

In the Qt (4.8.4) sources \src\gui\text\qcssparser_p.h header the QCss namespace is declared.

Whilst I haven't tried this, it looks like you will need to create a QCss::Parser, call parse to get a QCss::StyleSheet. This object contains the parsed data including a vector of QCss::StyleRule which matches QCss::Selector and QCss::Declaration together, have a look at the comment above the QCss::Declaration to see how it is all broken down.

Final Warning: Using Qt private interfaces is liable to cause maintenance problems - don't do it without a very good reason.

Silas Parker
  • 8,017
  • 1
  • 28
  • 43