Open In App

PyQt5 QColorDialog – How to execute it ?

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

In this article we will see how we can execute the QColorDialog widget, executing means to opening it. There are basically two ways of opening the QColorDialog one is to call the getColor method, this is a static way that will open the new instance of QColorDialog every time, this way is useful for quick uses but not preferred. The second way is by executing it, how the QColorDialog looks like.

In order to do this we use exec_() method with the QColorDialog object

Syntax : dialog.exec_()

Argument : It takes no argument

Action Performed : It opens the QColorDialog widget

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)
  
        # executing the dialog
        dialog.exec_()
  
  
        # creating label to display the color
        label = QLabel("GfG", self)
  
        # setting geometry to the label
        label.setGeometry(100, 100, 200, 60)
  
        # making label multi line
        label.setWordWrap(True)
  
        # setting stylesheet of the label
        label.setStyleSheet("QLabel"
                            "{"
                            "border : 5px solid black;"
                            "}")
  
        color = Qt.green
  
        # 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)
  
  
  
# 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
QColorDialog It is a dialog box of a color picker widget. A color picker is a graphical user interface widget, usually found within graphics software or online, used to select colors and sometimes to create color schemes. Below is how the QColorDialog looks like It is popup type widget in PyQt5 it basic use is to allow user to choose the color this
2 min read
PyQt5 QColorDialog - Getting Current Color
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 setCurren
2 min read
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 - 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 - 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 - Accepted Signal
In this article, we will see how we can get the accepted signal of the QColorDialog widget. This signal is emitted when the dialog has been accepted either by the user or by calling accept() or done() with the QDialog::Accepted argument. Note : This signal is not emitted when hiding the dialog with hide() or setVisible(false). This includes deletin
2 min read
PyQt5 QColorDialog - Finished Signal
In this article we will see how we can get the finished signal of the QColorDialog widget. This signal is emitted when the dialog's result code has been set, either by the user or by calling done(), accept(), or reject(). Note : This signal is not emitted when hiding the dialog with hide() or setVisible(false). This includes deleting the dialog whi
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