Skip to main content

Qt Stylesheet for PySide6, PySide2 and PyQt5.

Project description

Qt-Material

This is another stylesheet for PySide6, PySide2 and PyQt5, which looks like Material Design (close enough).

GitHub top language PyPI - License PyPI PyPI - Status PyPI - Python Version GitHub last commit CodeFactor Grade Documentation Status

There is some custom dark themes: dark And light: light

Navigation

Install

pip install qt-material

Usage

import sys
from PySide6 import QtWidgets
# from PySide2 import QtWidgets
# from PyQt5 import QtWidgets
from qt_material import apply_stylesheet

# create the application and the main window
app = QtWidgets.QApplication(sys.argv)
window = QtWidgets.QMainWindow()

# setup stylesheet
apply_stylesheet(app, theme='dark_teal.xml')

# run
window.show()
app.exec_()

Themes

from qt_material import list_themes

list_themes()
WARNING:root:qt_material must be imported after PySide or PyQt!





['dark_amber.xml',
 'dark_blue.xml',
 'dark_cyan.xml',
 'dark_lightgreen.xml',
 'dark_pink.xml',
 'dark_purple.xml',
 'dark_red.xml',
 'dark_teal.xml',
 'dark_yellow.xml',
 'light_amber.xml',
 'light_blue.xml',
 'light_cyan.xml',
 'light_cyan_500.xml',
 'light_lightgreen.xml',
 'light_pink.xml',
 'light_purple.xml',
 'light_red.xml',
 'light_teal.xml',
 'light_yellow.xml']

Custom colors

Color Tool is the best way to generate new themes, just choose colors and export as Android XML, the theme file must look like:

<!--?xml version="1.0" encoding="UTF-8"?-->
<resources>
<color name="primaryColor">#00e5ff</color>
<color name="primaryLightColor">#6effff</color>
<color name="secondaryColor">#f5f5f5</color>
<color name="secondaryLightColor">#ffffff</color>
<color name="secondaryDarkColor">#e6e6e6</color>
<color name="primaryTextColor">#000000</color>
<color name="secondaryTextColor">#000000</color>
</resources>

Save it as my_theme.xml or similar and apply the style sheet from Python.

apply_stylesheet(app, theme='dark_teal.xml')

Light themes

Light themes will need to add invert_secondary argument as True.

apply_stylesheet(app, theme='light_red.xml', invert_secondary=True)

Extra colors and custom fonts

There is an extra argument for accent colors and custom fonts.

extra = {

    # Button colors
    'danger': '#dc3545',
    'warning': '#ffc107',
    'success': '#17a2b8',

    # Font
    'font-family': 'Roboto',
}

apply_stylesheet(app, 'light_cyan.xml', invert_secondary=True, extra=extra)

The accent colors are applied to QPushButton with the corresponding class property:

pushButton_danger.setProperty('class', 'danger')
pushButton_warning.setProperty('class', 'warning')
pushButton_success.setProperty('class', 'success')

extra

Run examples

A window with almost all widgets (see the previous screenshots) are available to test all themes and create new ones.

git clone https://github.com/UN-GCPDS/qt-material.git
cd qt-material
python setup.py install
cd test
python main.py --PySide6

theme

New themes

Do you have a custom theme? it looks good? create a pull request in themes folder and share it with all users.

Change theme in runtime

There is a qt_material.QtStyleTools class that must be inherited along to QMainWindow for change themes in runtime using the apply_stylesheet() method.

class RuntimeStylesheets(QMainWindow, QtStyleTools):

    def __init__(self):
        super().__init__()
        self.main = QUiLoader().load('main_window.ui', self)

        self.apply_stylesheet(self.main, 'dark_teal.xml')
        # self.apply_stylesheet(self.main, 'light_red.xml')
        # self.apply_stylesheet(self.main, 'light_blue.xml')

run

Integrate stylesheets in a menu

A custom stylesheets menu can be added to a project for switching across all default available themes.

class RuntimeStylesheets(QMainWindow, QtStyleTools):

    def __init__(self):
        super().__init__()
        self.main = QUiLoader().load('main_window.ui', self)

        self.add_menu_theme(self.main, self.main.menuStyles)

menu

Create new themes

A simple interface is available to modify a theme in runtime, this feature can be used to create a new theme, the theme file is created in the main directory as my_theme.xml

class RuntimeStylesheets(QMainWindow, QtStyleTools):

    def __init__(self):
        super().__init__()
        self.main = QUiLoader().load('main_window.ui', self)

        self.show_dock_theme(self.main)

dock

A full set of examples are available in the exmaples directory

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

qt-material-2.4.tar.gz (7.3 MB view details)

Uploaded Source

Built Distributions

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

qt_material-2.4-py3.9.egg (7.3 MB view details)

Uploaded Egg

qt_material-2.4-py3-none-any.whl (7.3 MB view details)

Uploaded Python 3

File details

Details for the file qt-material-2.4.tar.gz.

File metadata

  • Download URL: qt-material-2.4.tar.gz
  • Upload date:
  • Size: 7.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1

File hashes

Hashes for qt-material-2.4.tar.gz
Algorithm Hash digest
SHA256 e643c283f6ee519040d3b21f2ff810490c41c33052dc92250650129f8a1beb83
MD5 119719b3c276574b4da43d3e31b941dd
BLAKE2b-256 0c7e291bc827295ef2c53ebe936d1e8b8ba1c65fa1a28270e85387849989a351

See more details on using hashes here.

File details

Details for the file qt_material-2.4-py3.9.egg.

File metadata

  • Download URL: qt_material-2.4-py3.9.egg
  • Upload date:
  • Size: 7.3 MB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1

File hashes

Hashes for qt_material-2.4-py3.9.egg
Algorithm Hash digest
SHA256 84e5667b6d892dfa4d06f60f4a24f861eb825772e79ea06a0c19b4352691f5fa
MD5 4964c10979648c1737b2bb5ad779382b
BLAKE2b-256 5bd83c25f9f5720f686b86a5fe89f0e2b124a40cf325377f8b568ef67d56079b

See more details on using hashes here.

File details

Details for the file qt_material-2.4-py3-none-any.whl.

File metadata

  • Download URL: qt_material-2.4-py3-none-any.whl
  • Upload date:
  • Size: 7.3 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1

File hashes

Hashes for qt_material-2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 e2c8d47bfe3e449ae1ff250dfa939ed9ff31ff47709e163aca24a8933ead10df
MD5 c8b16992fca21e9e306e12d43404f756
BLAKE2b-256 5173c2dc2e5dda9c1a69f48cf2b6769adbb8fa4a6449e6fb1ffedb69a0bd67f2

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