I would like to put the text of p.drawText (r.x () + 10, r.y () + 33, '{} / {}'. Format ('tset1', 'test2')
condition on the selected QCalendarWidget
date. But it is not good.
import sys
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
class main_window(QWidget):
def __init__(self):
super(main_window, self).__init__()
self.resize(1280, 900)
self.Calendar()
def Calendar(self):
self.cal = QCalendarWidget(self)
self.cal.resize(500, 500)
self.cal.clicked.connect(self.Calendar_click)
def Calendar_click(self):
p = QPainter()
r = QRect(0,0,10,10)
d = self.cal.selectedDate()
self.cal.paintCell(p, r, d)
if (d == QDate.currentDate()):
f = QFont()
f.setPixelSize(10)
f.setBold(True)
f.setItalic(True)
p.setFont(f)
p.drawText(r.x()+10, r.y()+33, '{}/{}'.format('tset1','test2'))
if __name__ == '__main__':
app = QApplication(sys.argv)
main = main_window()
main.show()
I've tried many, but I still do not know how to put small text on the selected date.
See Question&Answers more detail:os