Open In App

PyQt5 QColorDialog – Getting Current Color

Last Updated : 21 Jun, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

In this article we will see how we can get the current color of the QColorDialog widget. User can select the color with the mouse or using the spin boxes present there but the initial color always remain white in order to change this we can set the current of the color dialog before executing it. Current color is selected with the help of setCurrentColor method.

In order to do this we use currentColor method with the QColorDialog object

Syntax : dialog.currentColor()

Argument : It takes no argument

Return : It returns QColor object

Below is the implementation




# importing libraries
from PyQt5.QtWidgets import * 
from PyQt5 import QtCore, QtGui
from PyQt5.QtGui import * 
from PyQt5.QtCore import * 
import sys
  
  
class Window(QMainWindow):
  
    def __init__(self):
        super().__init__()
  
        # setting title
        self.setWindowTitle("Python ")
  
        # setting geometry
        self.setGeometry(100, 100, 500, 400)
  
        # calling method
        self.UiComponents()
  
        # showing all the widgets
        self.show()
  
  
    # method for components
    def UiComponents(self):
  
        # creating a QColorDialog object
        dialog = QColorDialog(self)
  
        # setting current color
        dialog.setCurrentColor(Qt.red)
  
        # executing the dialog
        dialog.exec_()
  
  
        # creating label 
        label = QLabel("GeeksforGeeks", self)
  
        # setting geometry to the label
        label.setGeometry(100, 100, 300, 80)
  
        # making label multi line
        label.setWordWrap(True)
  
        # setting stylesheet of the label
        label.setStyleSheet("QLabel"
                            "{"
                            "border : 5px solid black;"
                            "}")
  
        color = Qt.darkBlue
  
        # setting graphic effect to the label
        graphic = QGraphicsColorizeEffect(self)
  
        # setting color to the graphic
        graphic.setColor(color)
  
        # setting graphic to the label
        label.setGraphicsEffect(graphic)
  
        # getting the current color
        value = dialog.currentColor()
  
        # setting text to the label
        label.setText("Color : " + str(value))
  
  
  
  
# create pyqt5 app
App = QApplication(sys.argv)
  
# create the instance of our Window
window = Window()
  
# start the app
sys.exit(App.exec())


Output :



Similar Reads

PyQt5 QColorDialog - Setting Current Color
In this article we will see how we can set the current color of the QColorDialog widget. User can select the color with the mouse or using the spin boxes present there but the initial color always remain white in order to change this we can set the current of the color dialog before executing it. In order to do this we use setCurrentColor method wi
2 min read
PyQt5 QColorDialog - Current Color Changed Signal
In this article we will see how we can get the current color changed signal of the QColorDialog widget. This signal is emitted whenever the current color changes in the dialog. The current color can be changed by using mouse or keyboard also it can be changed programmatically with the help of setCurrentColor method In order to do this we use curren
2 min read
PyQt5 QColorDialog - Getting Color Dialog Options
In this article we will see how we can get the options of the QColorDialog widget. There are basically three dialog options available for the QColorDialog widget, below are the options - 1. ShowAlphaChannel : Allow the user to select the alpha component of a color 2. NoButtons : Don't display OK and Cancel buttons 3. DontUseNativeDialog : Use Qt's
2 min read
PyQt5 QColorDialog - Getting Custom Color
In this article we will see how we can get the custom color of the QColorDialog widget. Custom colors the color made by the user they can be set at the run time with the help of mouse although we can add custom color programmatically with the help of setCustomColor method, by default all custom colors are white. Below is how the custom color in col
2 min read
PyQt5 QColorDialog - Getting Layout
In this article we will see how we can get the layout of the QColorDialog. Layout is the map of all the child existed in the dialog, layout consist of the children of the dialog, each widget is added one by one in the layout. In order to do this we use layout method with the QColorDialog object Syntax : dialog.layout() Argument : It takes no argume
2 min read
PyQt5 QColorDialog - Getting Font
In this article we will see how we can get the font of QColorDialog. Font is the style i.e properties of the text present in the color dialog. We use setFont method to set the font to the dialog. Note : Increasing size of font will increase the size of the dialog box although dialog size is fixed In order to do this we use font method with the QCol
2 min read
PyQt5 QColorDialog - Setting Color Dialog Options
In this article we will see how we can set options of the QColorDialog widget. There are basically three dialog options available for the QColorDialog widget, below are the options 1. ShowAlphaChannel : Allow the user to select the alpha component of a color 2. NoButtons : Don't display OK and Cancel buttons 3. DontUseNativeDialog : Use Qt's standa
2 min read
PyQt5 QColorDialog - Accepting the color
In this article we will see how we can accept the QColorDialog widget. Accepting hides the modal dialog and sets the result code to accepted, it is same when user press 'OK' button. This method calls the finished signal In order to do this we use accept method with the QColorDialog object Syntax : dialog.accept() Argument : It takes no argument Ret
2 min read
PyQt5 QColorDialog - Rejecting the color
In this article we will see how we can reject the color in the QColorDialog widget. Hides the modal dialog and sets the result code to Rejected., it is same when user press 'Cancel' button. This method call the finished signal In order to do this we use reject method with the QColorDialog object Syntax : dialog.reject() Argument : It takes no argum
2 min read
PyQt5 QColorDialog - Making color done
In this article we will see how we can done the color in the QColorDialog widget. This closes the dialog and sets its result code to r. The finished signal will be emitted, if r is QDialog::Accepted or QDialog::Rejected, the accepted or the rejected signals will also be emitted, respectively. In order to do this we use done method with the QColorDi
2 min read