Open In App

PyQt5 QDateEdit – Getting Style Sheet

Last Updated : 07 Jul, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

In this article we will see how we can get the style sheet to the date edit. Setting style sheet makes the date edit look unique with the help of style sheet we can set color, border and many other things to the date edit. We can set style sheet with the help of setStyleSheet method.

In order to do this we use styleSheet method with the QDateEdit object

Syntax : date.styleSheet()

Argument : It takes no argument

Return : It returns string

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 QDateEdit widget
        date = QDateEdit(self)
  
        # setting geometry of the date edit
        date.setGeometry(100, 100, 200, 40)
  
        # alignment
        a_flag = Qt.AlignCenter
  
        # setting alignment of date
        date.setAlignment(a_flag)
  
        # setting style sheet
        date.setStyleSheet("QDateEdit"
                           "{"
                           "border : 2px solid black;"
                           "background : white;"
                           "padding : 5px;"
                           "}"
                           "QDateEdit::up-arrow"
                           "{"
                           "border : 2px solid black;"
                           "background-color : lightgreen;"
                           "}"
                           "QDateEdit::down-arrow"
                           "{"
                           "border : 2px solid black;"
                           "background-color : red;"
                           "}"
                           )
  
        # creating a label
        label = QLabel("GeeksforGeeks", self)
  
        # setting geometry
        label.setGeometry(100, 150, 250, 60)
  
        # making label multiline
        label.setWordWrap(True)
  
        # getting style sheet
        value = date.styleSheet()
  
  
        # setting text to the label
        label.setText("Style Sheet : " + 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 QDateEdit - Setting Style Sheet
In this article we will see how we can set style sheet to the date edit. Setting style sheet makes the date edit look unique with the help of style sheet we can set color, border and many other things to the date edit. In order to do this we use setStyleSheet method with the QDateEdit object Syntax : date.setStyleSheet(code) Argument : It takes str
2 min read
PyQt5 QDockWidget – Getting Style Sheet
In this article we will see how we can get style sheet of the QDockWidget. QDockWidget provides the concept of dock widgets, also know as tool palettes or utility windows. Dock windows are secondary windows placed in the dock widget area around the central widget in a QMainWindow(original window). Style sheet represents the style i.e look of the wi
2 min read
PyQt5 QScrollBar – Getting Style Sheet
In this article we will see how we can set style sheet to the QScrollBar. QScrollBar is a control that enables the user to access parts of a document that is larger than the widget used to display it. Slider is the scroll-able object inside the bar. Style sheet is the properties which are used to make the appearance better i.e by creating customize
2 min read
PyQt5 QListWidget – Getting Style Sheet
In this article we will see how we can get style sheet to the QListWidget. QListWidget is a convenience class that provides a list view with a classic item-based interface for adding and removing items. QListWidget uses an internal model to manage each QListWidgetItem in the list. Style sheet is the properties which are used to make the appearance
2 min read
PyQt5 QDateEdit - Getting Button Symbols
In this article we will see how we can get the button symbols of the QDateEdit. The date edit can two arrow buttons used for incrementing and decrementing the date, We can remove the buttons with the help of setButtonSymbols method and even after removing buttons there is no major effect on the functionality of the date edit. In order to do this we
2 min read
PyQt5 QDateEdit - Getting Correction Mode
In this article we will see how we can get the correction mode to the QDateEdit. In date edit correction is very important so that user can't enter invalid date for example if user try to enter the month value greater than 12 the current value goes back the previous valid value. In order to set the correction mode we use setCorrectionMode method, t
2 min read
PyQt5 QDateEdit - Getting Input Date
In this article we will see how we can get the input date of the QDateEdit. User can set date to the date edit with the help of cursor and the keyboard but sometimes there is a need of setting initial date or date programmatically for showing date in the records, which can be done with the help of setDate method.In order to do this we use date meth
2 min read
PyQt5 QDateEdit - Getting Date Time
In this article we will see how we can get the date time of the QDateEdit. User can set date to the date edit with the help of cursor and the keyboard but sometimes there is a need of setting initial date or date programmatically for showing date in the records, which can be done with the help of setDate method. Unlike normal date, date time has da
2 min read
PyQt5 QDateEdit - Getting Time
In this article we will see how we can get time to the QDateEdit. Unlike normal date, we can set date time to it with the help of setDate method. But also we can set only time as well without changing the date with the help of setTime method. In order to do this we use time method with the QDateEdit object Syntax : date.time() Argument : It takes n
2 min read
PyQt5 QDateEdit - Getting Date Alignment
In this article we will see how we can get the date alignment of the QDateEdit. By default, the text is aligned on the left hand side although by changing the alignment we can make the date appear in the center with the help of setAlignment method. Changing alignment does not effect the functionality of the date edit. In order to do this we use ali
2 min read
Practice Tags :