diff --git a/prettyqt/gui/brush.py b/prettyqt/gui/brush.py index e60a19c1d..24b1dc8c3 100644 --- a/prettyqt/gui/brush.py +++ b/prettyqt/gui/brush.py @@ -2,6 +2,7 @@ from prettyqt import constants, core, gui from prettyqt.qt import QtGui +from prettyqt.utils import InvalidParamError class Brush(QtGui.QBrush): @@ -33,6 +34,11 @@ def get_color(self) -> gui.Color: def get_style(self) -> constants.BrushStyleStr: return constants.BRUSH_STYLE.inverse[self.style()] + def set_style(self, style: constants.BrushStyleStr): + if style not in constants.BRUSH_STYLE: + raise InvalidParamError(style, constants.BRUSH_STYLE) + self.setStyle(constants.BRUSH_STYLE[style]) + if __name__ == "__main__": b = Brush() diff --git a/tests/test_gui.py b/tests/test_gui.py index f156404af..a1b0b3ccd 100644 --- a/tests/test_gui.py +++ b/tests/test_gui.py @@ -35,6 +35,10 @@ def test_repr(name, cls, qapp): def test_brush(): brush = gui.Brush() bytes(brush) + brush.set_style("cross") + with pytest.raises(InvalidParamError): + brush.set_style("test") + assert brush.get_style() == "cross" @pytest.mark.skipif(sys.platform == "darwin", reason="Somehow fails on OSX")