Skip to main content

Stylesheet Generator for PyQt{4-5}/PySide{1-2}

Project description

https://travis-ci.com/blambright/qstylizer.svg?branch=master https://readthedocs.org/projects/qstylizer/badge/?version=latest

Installation

pip install qstylizer

Documentation

Read the Docs.

Introduction

qstylizer is a python package designed to help with the construction of PyQt/PySide stylesheets.

import PyQt5.QtWidgets

import qstylizer.style

css = qstylizer.style.StyleSheet()
css.setValues(
    backgroundColor="green",
    color="#F0F0F0",
    marginLeft="2px"
)
css.QToolButton.setValues(
    border="1px transparent lightblue",
    borderRadius="3px",
    margin="1px",
    padding="3px"
)
css.QToolButton.menuButton.pressed.setValues(
    border="1px solid #333333",
    padding="5px",
    backgroundColor="#333333"
)
# The following is also valid and is equivalent to the statement above.
css["QToolButton::menu-button:pressed"].setValues(**{
    "border": "1px solid #333333",
    "padding": "5px",
    "background-color": "#333333",
})

css.QCheckBox.disabled.backgroundColor.setValue("#797979")

widget = PyQt5.QtWidgets.QWidget()
widget.setStyleSheet(css.toString())

The stylesheet generated above looks like this when passed to setStyleSheet():

* {
    color: #F0F0F0;
    margin-left: 2px;
    background-color: green;
}
QToolButton {
    border-radius: 3px;
    padding: 3px;
    border: 1px transparent lightblue;
    margin: 1px;
}
QToolButton::menu-button:pressed {
    padding: 5px;
    border: 1px solid #333333;
    background-color: #333333;
}
QCheckBox:disabled {
    background-color: #797979;
}

The true power comes from parsing an existing stylesheet and tweaking individual property values.

import qstylizer.parser

css = qstylizer.parser.parse(
    """
    QToolButton::menu-button:pressed {
        padding: 5px;
        border: 1px solid #333333;
        background-color: #333333;
    }
    QCheckBox:disabled {
        background-color: #797979;
    }
    """
)
css.QToolButton.menuButton.pressed.padding.setValue("10px")
css.QCheckBox.disabled.backgroundColor.setValue("#222222")

print(css.toString())

Output:

QToolButton::menu-button:pressed {
    padding: 10px;
    border: 1px solid #333333;
    background-color: #333333;
}
QCheckBox:disabled {
    background-color: #222222;
}

License

MIT License

Copyright (c) 2018 Brett Lambright

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qstylizer-0.2.3.tar.gz (25.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qstylizer-0.2.3-py2.py3-none-any.whl (15.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file qstylizer-0.2.3.tar.gz.

File metadata

  • Download URL: qstylizer-0.2.3.tar.gz
  • Upload date:
  • Size: 25.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.7

File hashes

Hashes for qstylizer-0.2.3.tar.gz
Algorithm Hash digest
SHA256 5f2f5eb2c65c6c45e950462b565fcaa5107a91d1cfc1a85b8e0d831d727ee8f6
MD5 b80af8c7993bf398c65d8c9b69d0ed4d
BLAKE2b-256 b4526f205653ca182ed808dce57059387d3635fcc1abefdb29895e73d1303718

See more details on using hashes here.

File details

Details for the file qstylizer-0.2.3-py2.py3-none-any.whl.

File metadata

  • Download URL: qstylizer-0.2.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 15.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.7

File hashes

Hashes for qstylizer-0.2.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 993b2b7c69b76fedfb8c281308bd7874e130d12701fa2b64f219fd83e8f22496
MD5 e6af380c7737ef74a1b493e5a18bdf2a
BLAKE2b-256 5ed010c4c930ab86983d9c51b7ddffec31ebeacae39b003df3a4159f685dc030

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page