How to use PyQtDarkTheme#

Apply dark theme to your Qt Application#

PyQtDarkTheme applies a flat theme to your Qt applications.

import sys

from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton

import qdarktheme

app = QApplication(sys.argv)
# Apply dark theme.
qdarktheme.setup_theme()

main_win = QMainWindow()
push_button = QPushButton("PyQtDarkTheme!!")
main_win.setCentralWidget(push_button)

main_win.show()

app.exec()
import sys

from PyQt6.QtWidgets import QApplication, QMainWindow, QPushButton

import qdarktheme

app = QApplication(sys.argv)
# Apply dark theme.
qdarktheme.setup_theme()

main_win = QMainWindow()
push_button = QPushButton("PyQtDarkTheme!!")
main_win.setCentralWidget(push_button)

main_win.show()

app.exec()
import sys

from PySide2.QtWidgets import QApplication, QMainWindow, QPushButton

import qdarktheme

# Enable HiDPI.
qdarktheme.enable_hi_dpi()

app = QApplication(sys.argv)
# Apply dark theme.
qdarktheme.setup_theme()

main_win = QMainWindow()
push_button = QPushButton("PyQtDarkTheme!!")
main_win.setCentralWidget(push_button)

main_win.show()

app.exec_()
import sys

from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton

import qdarktheme

# Enable HiDPI.
qdarktheme.enable_hi_dpi()

app = QApplication(sys.argv)
# Apply dark theme.
qdarktheme.setup_theme()

main_win = QMainWindow()
push_button = QPushButton("PyQtDarkTheme!!")
main_win.setCentralWidget(push_button)

main_win.show()

app.exec()
import pyqtgraph as pg
from pyqtgraph.Qt.QtGui import QMainWindow, QPushButton

import qdarktheme

app = pg.mkQApp()
# Apply dark theme.
qdarktheme.setup_theme()

main_win = QMainWindow()
push_button = QPushButton("PyQtDarkTheme!!")
main_win.setCentralWidget(push_button)

main_win.show()

pg.exec()

Enable HiDPI#

If you want to enable HiDPI, you can use qdarktheme.enable_hi_dpi(). For Qt6 bindings, HiDPI “just works” without using this function.

# enable_hi_dpi() must be called before instantiation of QApplication.
qdarktheme.enable_hi_dpi()
app = QApplication(sys.argv)

Toggle dark/light Theme#

If you add theme argument as “auto”, your Qt Application sync with OS’s theme. On macOS, qdarktheme also syncs with accent colors.

qdarktheme.setup_theme("auto")
import sys

from PyQt6.QtWidgets import QApplication, QMainWindow, QPushButton

import qdarktheme

app = QApplication(sys.argv)
qdarktheme.setup_theme("auto")

main_win = QMainWindow()
push_button = QPushButton("PyQtDarkTheme!!")
main_win.setCentralWidget(push_button)

main_win.show()

app.exec()

You can also switch between light and dark theme manually.

combo_box = QComboBox()
combo_box.addItems(qdarktheme.get_themes())
combo_box.currentTextChanged.connect(qdarktheme.setup_theme)
import sys

from PyQt6.QtWidgets import QApplication, QComboBox, QHBoxLayout, QMainWindow, QWidget

import qdarktheme

app = QApplication(sys.argv)
qdarktheme.setup_theme("dark")

main_win = QMainWindow()

combo_box = QComboBox()
combo_box.addItems(qdarktheme.get_themes())
combo_box.currentTextChanged.connect(qdarktheme.setup_theme)

layout = QHBoxLayout()
layout.addWidget(combo_box)

central_widget = QWidget()
central_widget.setLayout(layout)
main_win.setCentralWidget(central_widget)

main_win.show()

app.exec()

Toggle dark/light Theme with pyqtgraph#

You can also switch between light and dark theme with pyqtgraph.

def toggle_theme(theme) -> None:
    qdarktheme.setup_theme(theme)
    plot_widget.setBackground("k" if theme == "dark" else "w")


signal.connect(toggle_theme)
import sys

import pyqtgraph as pg
from PySide6.QtCore import Slot
from PySide6.QtWidgets import QApplication, QComboBox, QMainWindow, QVBoxLayout, QWidget

import qdarktheme

app = QApplication(sys.argv)
qdarktheme.setup_theme

main_win = QMainWindow()
combo_box = QComboBox()
plot_widget = pg.PlotWidget()


@Slot(str)
def toggle_theme(theme) -> None:
    qdarktheme.setup_theme(theme)
    plot_widget.setBackground("k" if theme == "dark" else "w")


combo_box.addItems(qdarktheme.get_themes())
combo_box.currentTextChanged.connect(toggle_theme)

layout = QVBoxLayout()
layout.addWidget(combo_box)
layout.addWidget(plot_widget)

central_widget = QWidget()
central_widget.setLayout(layout)
main_win.setCentralWidget(central_widget)

main_win.show()

app.exec()

Theme customization#

You can customize theme color.

qdarktheme.setup_theme(custom_colors={"primary": "#D0BCFF"})
import sys

from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton

import qdarktheme

app = QApplication(sys.argv)
# Customize accent color.
qdarktheme.setup_theme(custom_colors={"primary": "#D0BCFF"})

main_win = QMainWindow()
main_win.setContentsMargins(10, 10, 10, 10)
push_button = QPushButton("PyQtDarkTheme!!")
main_win.setCentralWidget(push_button)

main_win.show()

app.exec()
_images/customize_accent_color.png

You can also change border corner shape.

qdarktheme.setup_theme(corner_shape="sharp")
import sys

from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton

import qdarktheme

app = QApplication(sys.argv)
# Change border corner shape to sharp.
qdarktheme.setup_theme(corner_shape="sharp")

main_win = QMainWindow()
main_win.setContentsMargins(10, 10, 10, 10)
push_button = QPushButton("PyQtDarkTheme!!")
main_win.setCentralWidget(push_button)

main_win.show()

app.exec()
_images/change_corner_to_sharp.png

Append your own stylesheets#

qss = """
QPushButton {
    border-width: 2px;
    border-style: dashed;
}
"""
qdarktheme.setup_theme(additional_qss=qss)
import sys

from PyQt6.QtWidgets import QApplication, QMainWindow, QPushButton

import qdarktheme

app = QApplication(sys.argv)
# Additional stylesheet
qss = """
QPushButton {
    border-width: 2px;
    border-style: dashed;
}
"""
qdarktheme.setup_theme(additional_qss=qss)

main_win = QMainWindow()
main_win.setContentsMargins(10, 10, 10, 10)
push_button = QPushButton("PyQtDarkTheme!!")
main_win.setCentralWidget(push_button)

main_win.show()

app.exec()
_images/append_stylesheet.png

Use overridden Qt default icons#

If you setup theme with qdarktheme.setup_theme, qdarktheme override QStyle.standardIcon(). So you can easily use some Google Material Design Icons. And these icons change color that adjust to theme when theme is changed.

save_pixmap = QStyle.StandardPixmap.SP_DialogSaveButton
save_icon = win.style().standardIcon(save_pixmap)

push_button = QPushButton("Save")
push_button.setIcon(save_icon)
import sys

from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton, QStyle

import qdarktheme

app = QApplication(sys.argv)
qdarktheme.setup_theme()

main_win = QMainWindow()
save_pixmap = QStyle.StandardPixmap.SP_DialogSaveButton
save_icon = main_win.style().standardIcon(save_pixmap)

push_button = QPushButton("Save")
push_button.setIcon(save_icon)
main_win.setCentralWidget(push_button)

main_win.show()

app.exec()
_images/use_standard_icons.png
_images/standard_icons.png

Use QPalette to your Qt Application#

You can apply dark and light color to your Qt Application using QPalette of PyQtDarkTheme.

qdarktheme.load_palette()
import sys

from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton

import qdarktheme

app = QApplication(sys.argv)
main_win = QMainWindow()
push_button = QPushButton("PyQtDarkTheme!!")
main_win.setCentralWidget(push_button)

# Apply dark theme
app.setPalette(qdarktheme.load_palette())

main_win.show()

app.exec()
_images/widget_gallery_dark_qpalette.png

And you can get theme color from QPalette of PyQtDarkTheme.

import qdarktheme

dark_palette = qdarktheme.load_palette()
link_color = dark_palette.link().color()
link_rgb = link_color.getRgb()

Use stylesheet#

If you want to use Qt stylesheet of PyQtDarkTheme, use following function.

qdarktheme.load_stylesheet()
import sys

from PyQt6.QtWidgets import QApplication, QMainWindow, QPushButton

import qdarktheme

app = QApplication(sys.argv)
# Apply stylesheet as "dark" theme
app.setStyleSheet(qdarktheme.load_stylesheet())

main_win = QMainWindow()
push_button = QPushButton("PyQtDarkTheme!!")
main_win.setCentralWidget(push_button)

main_win.show()

app.exec()