Giter Club home page Giter Club logo

pyqt-color-picker's Introduction

pyqt-color-picker

PyQt color picker dialog which contains color picker widget.

You can either use dialog or widget.

Requirements

PyQt5 >= 5.8

Setup

python -m pip install pyqt-color-picker

Class, Method Overview

ColorPickerDialog

  • ColorPickerDialog(color=QColor(255, 255, 255), orientation='horizontal')
    • color argument's type can be QColor or str.
    • orientation argument decides the overall layout direction of the dialog. There are two values. 'horizontal', 'vertical'. See layout preview below.
  • getColor() -> QColor - get the color.

If you only want to use this as a part of window(not as whole dialog), use ColorPickerWidget(color=QColor(255, 255, 255), orientation='horizontal'). See the example below.

ColorPickerWidget

  • colorChanged(color: QColor) - signal. After color being changed, this will be emitted.
  • getCurrentColor() -> QColor - get the current color.
  • setCurrentColor(QColor|str) - set the current color.

Layout type

Horizontal

image

Vertical

image

Usage

Dialog

Code Sample

dialog = ColorPickerDialog()
reply = dialog.exec()
if reply == QDialog.Accepted: 
  color = dialog.getColor() # return type is QColor
  //..

Result

example.mp4

Using as a part of window

Code Sample

from PyQt5.QtWidgets import QMainWindow, QApplication, QHBoxLayout, QWidget, QTextEdit
from pyqt_color_picker import ColorPickerWidget


class Window(QMainWindow):
    def __init__(self):
        super().__init__()
        self.__initUi()

    def __initUi(self):
        self.__te = QTextEdit()
        self.__colorPicker = ColorPickerWidget(orientation='vertical')
        self.__colorPicker.colorChanged.connect(self.colorChanged) # when color has changed, call the colorChanged function
        lay = QHBoxLayout()
        lay.addWidget(self.__te)
        lay.addWidget(self.__colorPicker)
        mainWidget = QWidget()
        mainWidget.setLayout(lay)
        self.setCentralWidget(mainWidget)

    def colorChanged(self, color):
        self.__te.setStyleSheet(f'QTextEdit {{ color: {color.name()} }}')


if __name__ == "__main__":
    import sys

    app = QApplication(sys.argv)
    ex = Window()
    ex.show()
    sys.exit(app.exec_())

Result

pyqt_color_picker_example.mp4

pyqt-color-picker's People

Contributors

yjg30737 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.