OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to make a rounding for a user-selected date? QCalendar PyQt6

  • Thread starter Thread starter Vyacheslav Erl
  • Start date Start date
V

Vyacheslav Erl

Guest
Implemented at the moment

Layout. The date in the layout does not match the contents of the calendar

How to make a rounding for a user-selected date in QCalendar. I'm using PyQt6.

CalendarWidget.py:

Code:
from __init__ import *

class CalendarWidget(QCalendarWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setGridVisible(False)
        self.setVerticalHeaderFormat(QCalendarWidget.VerticalHeaderFormat.NoVerticalHeader)
        self.setHorizontalHeaderFormat(QCalendarWidget.HorizontalHeaderFormat.NoHorizontalHeader)
        self.setSelectedDate(QDate.currentDate())
        self.setNavigationBarVisible(False)

        for dayOff in (Qt.DayOfWeek.Saturday, Qt.DayOfWeek.Sunday):
            format = self.weekdayTextFormat(dayOff)
            format.setForeground(QColor("#CAD3F5"))
            self.setWeekdayTextFormat(dayOff, format)

    def paintCell(self, painter, rect, date):
        if not date.month() == self.selectedDate().month():
            painter.save()
            painter.setPen(QPen(QColor("#939ab7")))
            painter.drawText(rect, int(Qt.AlignmentFlag.AlignCenter), str(date.day()))
            painter.restore()
        else:
            QCalendarWidget.paintCell(self, painter, rect, date)

Ideally, the fillet should be 45px, according to the layout.
<p><a href="https://i.sstatic.net/TpB8aThJ.png" rel="nofollow noreferrer">Implemented at the moment</a></p>
<p><a href="https://i.sstatic.net/og6Fs2A4.png" rel="nofollow noreferrer">Layout. The date in the layout does not match the contents of the calendar</a></p>
<p>How to make a rounding for a user-selected date in QCalendar. I'm using PyQt6.</p>
<p>CalendarWidget.py:</p>
<pre><code>from __init__ import *

class CalendarWidget(QCalendarWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.setGridVisible(False)
self.setVerticalHeaderFormat(QCalendarWidget.VerticalHeaderFormat.NoVerticalHeader)
self.setHorizontalHeaderFormat(QCalendarWidget.HorizontalHeaderFormat.NoHorizontalHeader)
self.setSelectedDate(QDate.currentDate())
self.setNavigationBarVisible(False)

for dayOff in (Qt.DayOfWeek.Saturday, Qt.DayOfWeek.Sunday):
format = self.weekdayTextFormat(dayOff)
format.setForeground(QColor("#CAD3F5"))
self.setWeekdayTextFormat(dayOff, format)

def paintCell(self, painter, rect, date):
if not date.month() == self.selectedDate().month():
painter.save()
painter.setPen(QPen(QColor("#939ab7")))
painter.drawText(rect, int(Qt.AlignmentFlag.AlignCenter), str(date.day()))
painter.restore()
else:
QCalendarWidget.paintCell(self, painter, rect, date)
</code></pre>
<p>Ideally, the fillet should be 45px, according to the layout.</p>
 
Top