0

I have to create a couple of custom qt widgets, some of which use custom drawing. Those widgets should be styled via the companies qt stylesheet.

This creates the problem that some custom widget need to retrieve a value from stylesheet that has been applied to the QMainWindow or QApplication. This value could either be one of qt's official properties or some custom qproperty-... property

However, it is not trivial to access them from the widget. One option would be to get the stylesheet string and manually parse/regex out the values I am interested in. This is obviously a terrible solution, as qt must already have some functionality to parse the stylesheet data which is used during drawing the official qt widgets.

... Qt creates a QStyle sub-class called QStyleSheetStyle.That means you can query style sheet information via the normal QStyle methods ...

Problem 1)

This post addresses this idea, but unfortunately doesn't go into detail how to actually achieve this. With my lack of experience, I wasn't able to find out how to do this, even after diving into qt's source.

Problem 2)

I assume that this would only apply to regular qt properties (and not custom qproperty-... properties). Is there a better way to access them compared to this approach?

# example for retrieving qproperty-offset
def get_offset(self):
    return self._offset

def set_offset(self, offset:int):
    self._offset = offset
    self.update()

offset = QtCore.Property(int, get_offset, set_offset)
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
hdmjt
  • 25
  • 3

1 Answers1

1

No, it is currently not possible since the implementation of Qt Style Sheet is through a QStyle that is part of the private Qt API, in Qt6 it is intended to expose that style. So the solution to get properties from the stylesheet is through qproperty.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • Thanks for clarifying. Can you use QtCore.Property to get "official" properties as well or only those starting with the qproperty-... prefix? Plus , unfortunately https://wiki.qt.io/New_Features_in_Qt_6.0 doesn't seem to contain the QStyle fix you described. – hdmjt Nov 29 '20 at 21:25
  • How should I query the properties in the item delegates paint method? – ManuelSchneid3r Jun 28 '23 at 07:41