Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create custom palette. #292

Open
Anandir opened this issue Aug 25, 2021 · 1 comment
Open

Create custom palette. #292

Anandir opened this issue Aug 25, 2021 · 1 comment

Comments

@Anandir
Copy link

Anandir commented Aug 25, 2021

Hi everyone.
First of all, thanks for your hard work.
I've tried, with no luck, to create a custom color palette for an application I'm going to develop.
How can I create a custom palette of colors and, subsequently, the .qss file for the application?
I've looked at the Python code, but I didn't really spot a way to do so.

Even if the snippet on the scss.py file worked.
And I don't really understand what I'm doing wrong.

Do you have any ideas?

Best regards
Giacomo

@GijsGroote
Copy link

Look at the Palette class and create your own subclass. Do take some inspiration from light palette
or dark palette. You might also need the color system.

Then use the palette class (not instance) as arguement when loading the style sheet. Example here with LightPalette

import sys
import qdarkstyle
from qdarkstyle.light.palette import LightPalette
from PyQt6.QtWidgets import QWidget, QMainWindow, QApplication, QPushButton, QLineEdit, QLabel, QVBoxLayout

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        
        # Set window title and size
        self.setWindowTitle("Example PyQt6 App")
        self.setGeometry(100, 100, 400, 300)

        # Create central widget and set layout
        central_widget = QWidget()
        layout = QVBoxLayout()

        # Add a button
        button = QPushButton("Click Me")
        layout.addWidget(button)

        # Add a text input field
        input_field = QLineEdit()
        input_field.setPlaceholderText("Enter something here...")
        layout.addWidget(input_field)

        # Add a label for random stuff
        label = QLabel("Random Label")
        layout.addWidget(label)

        # Add some more random stuff (another button)
        another_button = QPushButton("Another Button")
        layout.addWidget(another_button)

        # Set the layout to the central widget
        central_widget.setLayout(layout)
        self.setCentralWidget(central_widget)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = MainWindow()

    # Apply the darkstyle theme using a light palette
    window.setStyleSheet(qdarkstyle.load_stylesheet(
        palette=LightPalette
    ))

    window.show()
    sys.exit(app.exec())

I've only tested using the light palette. Could you report back if creating a subclass works?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants