PyQt5 控件学习(一个一个学习之QCalendarWidget)

QCalendarWidget 的继承图:

QCalendarWidget 的描述:

它的区域划分:

QCalendarWidget 的继承:

它继承自QWidget  

QCalendarWidget 的功能作用:

QCalendarWidget 的功能作用之构造函数:

from PyQt5.Qt import * #刚开始学习可以这样一下导入
import sys

class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("QCalendarWidget 的学习")
        self.resize(400,400)
        self.set_ui() 


    def set_ui(self):
        calendarWidget = QCalendarWidget(self)


if __name__ == '__main__':
    app =QApplication(sys.argv)

    window = Window()
    window.show()

    sys.exit(app.exec_())
View Code

这里的不是弹出来的,它是直接放到window 父控件里面的!

QCalendarWidget 的功能作用之日期范围:

from PyQt5.Qt import * #刚开始学习可以这样一下导入
import sys

class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("QCalendarWidget 的学习")
        self.resize(400,400)
        self.set_ui()


    def set_ui(self):
        calendarWidget = QCalendarWidget(self)

        # calendarWidget.setSelectedDate(QDate(-9999,1,1))

        # calendarWidget.setMinimumDate(QDate(1949,10,1))
        # calendarWidget.setMaximumDate(QDate(2049,10,1))
        calendarWidget.setDateRange(QDate(1949,1,1),QDate(2049 ,1,1))



if __name__ == '__main__':
    app =QApplication(sys.argv)

    window = Window()
    window.show()

    sys.exit(app.exec_())
View Code

QCalendarWidget 的功能作用之日期编辑:

from PyQt5.Qt import * #刚开始学习可以这样一下导入
import sys

class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("QCalendarWidget 的学习")
        self.resize(400,400)
        self.set_ui()


    def set_ui(self):
        calendarWidget = QCalendarWidget(self)


        calendarWidget.setDateRange(QDate(1949,1,1),QDate(2049 ,1,1))

        # calendarWidget.setDateEditEnabled(False)  #这样就不能在日期上直接改了
        calendarWidget.setDateEditAcceptDelay(3000)  #3s 编辑结束3s才会跳转过去


if __name__ == '__main__':
    app =QApplication(sys.argv)

    window = Window()
    window.show()

    sys.exit(app.exec_())
View Code

QCalendarWidget 的功能作用之日期获取:

from PyQt5.Qt import * #刚开始学习可以这样一下导入
import sys

class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("QCalendarWidget 的学习")
        self.resize(400,400)
        self.set_ui()


    def set_ui(self):
        calendarWidget = QCalendarWidget(self)


        calendarWidget.setDateRange(QDate(1949,1,1),QDate(2049 ,1,1))

        # calendarWidget.setDateEditEnabled(False)  #这样就不能在日期上直接改了
        calendarWidget.setDateEditAcceptDelay(3000)  #3s 编辑结束3s才会跳转过去
        
        btn = QPushButton(self)
        btn.setText("按钮")
        btn.move(0,300)

        btn.clicked.connect(lambda :print(calendarWidget.yearShown()))
        btn.clicked.connect(lambda :print(calendarWidget.monthShown()))
        btn.clicked.connect(lambda :print(calendarWidget.selectedDate()))



if __name__ == '__main__':
    app =QApplication(sys.argv)

    window = Window()
    window.show()

    sys.exit(app.exec_())
View Code

使用最多的是最后一个

QCalendarWidget 的功能作用之格式外观:

from PyQt5.Qt import * #刚开始学习可以这样一下导入
import sys

class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("QCalendarWidget 的学习")
        self.resize(400,400)
        self.set_ui()


    def set_ui(self):
        calendarWidget = QCalendarWidget(self)



        #设置导航条
        # calendarWidget.setNavigationBarVisible(False)

        # calendarWidget.setFirstDayOfWeek(Qt.Monday)

        # calendarWidget.setGridVisible(True)





if __name__ == '__main__':
    app =QApplication(sys.argv)

    window = Window()
    window.show()

    sys.exit(app.exec_())
View Code

from PyQt5.Qt import * #刚开始学习可以这样一下导入
import sys

class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("QCalendarWidget 的学习")
        self.resize(400,400)
        self.set_ui()


    def set_ui(self):
        calendarWidget = QCalendarWidget(self)



        #设置文本格式
        textCharFormat = QTextCharFormat()
        textCharFormat.setFontFamily("隶书")
        textCharFormat.setFontPointSize(16)
        textCharFormat.setFontUnderline(True)

        calendarWidget.setHeaderTextFormat(textCharFormat)

        # calendarWidget.setHorizontalHeaderFormat(QCalendarWidget.LongDayNames)
        # calendarWidget.setHorizontalHeaderFormat(QCalendarWidget.NoHorizontalHeader)
        # calendarWidget.setVerticalHeaderFormat(QCalendarWidget.NoVerticalHeader)


        calendarWidget.setWeekdayTextFormat(Qt.Tuesday,textCharFormat)

        calendarWidget.setDateTextFormat(QDate(2019,8,22),textCharFormat)




if __name__ == '__main__':
    app =QApplication(sys.argv)

    window = Window()
    window.show()

    sys.exit(app.exec_())
View Code

QCalendarWidget 的功能作用之选中:

from PyQt5.Qt import * #刚开始学习可以这样一下导入
import sys

class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("QCalendarWidget 的学习")
        self.resize(400,400)
        self.set_ui()


    def set_ui(self):
        calendarWidget = QCalendarWidget(self)

        #使鼠标不能点
        calendarWidget.setSelectionMode(QCalendarWidget.NoSelection)


        # #
        # calendarWidget.setSelectedDate(QDate(2019,11,11))




if __name__ == '__main__':
    app =QApplication(sys.argv)

    window = Window()
    window.show()

    sys.exit(app.exec_())
View Code

QCalendarWidget 的功能作用之常用的方法:

from PyQt5.Qt import * #刚开始学习可以这样一下导入
import sys

class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("QCalendarWidget 的学习")
        self.resize(400,400)
        self.set_ui()


    def set_ui(self):
        calendarWidget = QCalendarWidget(self)
        self.calendarWidget = calendarWidget

        btn = QPushButton(self)
        btn.setText("按钮")
        btn.move(0,300)
        btn.clicked.connect(self.btn_clicked_slot)


    def btn_clicked_slot(self):
        # self.calendarWidget.showToday()
        # self.calendarWidget.showSelectedDate()
        # self.calendarWidget.showNextYear()
        # self.calendarWidget.showNextMonth()
        # self.calendarWidget.showPreviousMonth()
        # self.calendarWidget.showPreviousMonth()
        self.calendarWidget.setCurrentPage(2008,8)

        self.calendarWidget.setFocus()




if __name__ == '__main__':
    app =QApplication(sys.argv)

    window = Window()
    window.show()

    sys.exit(app.exec_())
View Code

QCalendarWidget 的信号:

from PyQt5.Qt import * #刚开始学习可以这样一下导入
import sys

class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("QCalendarWidget 的学习")
        self.resize(400,400)
        self.set_ui()


    def set_ui(self):
        calendarWidget = QCalendarWidget(self)
        self.calendarWidget = calendarWidget

        #信号
        # calendarWidget.activated.connect(lambda val:print(val))
        # calendarWidget.clicked.connect(lambda val:print(val))
        # calendarWidget.currentPageChanged.connect(lambda y,m:print(y,m))
        calendarWidget.selectionChanged.connect(lambda :print("选中日期改变",calendarWidget.selectedDate()))




if __name__ == '__main__':
    app =QApplication(sys.argv)

    window = Window()
    window.show()

    sys.exit(app.exec_())
View Code

总结:

到此,所有的输入控件都已经说完了,

输入控件大汇总:

下面是展示控件:

我们这里首先看的是QLabel 控件:https://www.cnblogs.com/zach0812/p/11395402.html 

猜你喜欢

转载自www.cnblogs.com/zach0812/p/11394594.html