久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  1. <tfoot id='e14Bn'></tfoot>
      <bdo id='e14Bn'></bdo><ul id='e14Bn'></ul>

    <i id='e14Bn'><tr id='e14Bn'><dt id='e14Bn'><q id='e14Bn'><span id='e14Bn'><b id='e14Bn'><form id='e14Bn'><ins id='e14Bn'></ins><ul id='e14Bn'></ul><sub id='e14Bn'></sub></form><legend id='e14Bn'></legend><bdo id='e14Bn'><pre id='e14Bn'><center id='e14Bn'></center></pre></bdo></b><th id='e14Bn'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='e14Bn'><tfoot id='e14Bn'></tfoot><dl id='e14Bn'><fieldset id='e14Bn'></fieldset></dl></div>

  2. <small id='e14Bn'></small><noframes id='e14Bn'>

      <legend id='e14Bn'><style id='e14Bn'><dir id='e14Bn'><q id='e14Bn'></q></dir></style></legend>

      在 QCalendarWidget 中將項目添加到 QTableView

      Adding items to a QTableView within QCalendarWidget(在 QCalendarWidget 中將項目添加到 QTableView)

            <tbody id='nplUD'></tbody>
          <legend id='nplUD'><style id='nplUD'><dir id='nplUD'><q id='nplUD'></q></dir></style></legend>

          <small id='nplUD'></small><noframes id='nplUD'>

          1. <i id='nplUD'><tr id='nplUD'><dt id='nplUD'><q id='nplUD'><span id='nplUD'><b id='nplUD'><form id='nplUD'><ins id='nplUD'></ins><ul id='nplUD'></ul><sub id='nplUD'></sub></form><legend id='nplUD'></legend><bdo id='nplUD'><pre id='nplUD'><center id='nplUD'></center></pre></bdo></b><th id='nplUD'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='nplUD'><tfoot id='nplUD'></tfoot><dl id='nplUD'><fieldset id='nplUD'></fieldset></dl></div>
            • <tfoot id='nplUD'></tfoot>
                <bdo id='nplUD'></bdo><ul id='nplUD'></ul>

              • 本文介紹了在 QCalendarWidget 中將項目添加到 QTableView的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我目前正在制作一個帶有日歷的待辦事項應用程序.每當用戶在特定日期有事件時,左上角會出現一個紅色圓圈.每當用戶雙擊日期時,我希望它顯示一個包含當天事件信息的新窗口.但是,我無法將信息存儲到每個日期中.我怎樣才能使每個日期都有一個可以存儲事件的列表?

                I'm currently making a to-do application which has a calendar. Whenever the user has an event on a specific date, A red circle appears in the top left corner. Whenever the user double clicks on the date, I want it to display a new window with information on event for the day. However, I am having trouble storing information into each date. How can I make it so each date has a sort of list that can store events?

                這是用戶界面:

                這是子類 QCalendarWidget 的代碼:

                Here is the code for the subclassed QCalendarWidget:

                class TodoCalendar(QtWidgets.QCalendarWidget):
                    def __init__(self, list_of_events, *args, **kwargs):
                        super().__init__(*args, **kwargs)
                        self.list_of_events = list_of_events
                        //list_of_events is a list of all events the user has created
                
                        self.table = self.findChild(QtWidgets.QTableView)
                        self.table.viewport().installEventFilter(self)
                
                    def paintCell(self, painter, rect, date):
                        super().paintCell(painter, rect, date)
                        for event in self.list_of_events.values():
                            if event.due_time == date:
                                painter.setBrush(Qt.red)
                                painter.drawEllipse(rect.topLeft() + QPoint(12, 7), 3, 3)
                
                    def eventFilter(self, source, event):
                        if (event.type() == QtCore.QEvent.MouseButtonDblClick and source is self.table.viewport()):
                            index = self.table.indexAt(event.pos())
                            print(f"row: {index.row()}, column: {index.column()}, text: {index.data()}")
                        return super().eventFilter(source, event)
                

                這里還有 list_of_events 的列表:

                Also here is the list for list_of_events:

                {'test changed': <CustomWidgets.TodoEvent object at 0x00000230A5A72908>, 'due 10/8': <CustomWidgets.TodoEvent object at 0x00000230A5AA5080>, 'also due 10/9': <CustomWidgets.TodoEvent object at 0x00000230A5AC4B00>, 'also due 10/9 too': <CustomWidgets.TodoEvent object at 0x00000230A5AD0550>, 'due 10/9 too too': <CustomWidgets.TodoEvent object at 0x00000230A5AD0A90>, '10/9 2': <CustomWidgets.TodoEvent object at 0x00000230A5AD6438>, '10/10': <CustomWidgets.TodoEvent object at 0x00000230A5AD64A8>, '10/10 also': <CustomWidgets.TodoEvent object at 0x00000230A5AD64E0>, '10/10 2': <CustomWidgets.TodoEvent object at 0x00000230A5AD6550>, '10/10 3': <CustomWidgets.TodoEvent object at 0x00000230A5AD65C0>, '10/10 4': <CustomWidgets.TodoEvent object at 0x00000230A5AD6630>, 'due 10/9 changed': <CustomWidgets.TodoEvent object at 0x00000230A5AD6668>}
                

                每個 toDoEvent 都有一個標題、到期時間、提醒時間和描述

                each toDoEvent has a title, due_time, remind_time, and description

                推薦答案

                另一種方法是獲取給定行和列的日期,然后過濾事件.

                Instead of storing in some event by date another approach is to get the date given the row and column, and then filter the events.

                問題是沒有公共方法來計算給定行和列的日期,所以我的解決方案使用 Qt 私有 API 代碼.

                The problem is that there is no public method to calculate the date given the row and column, so my solution uses the Qt private API code.

                綜合以上,解決辦法是:

                Considering the above, the solution is:

                import random
                from dataclasses import dataclass
                
                from PyQt5 import QtCore, QtGui, QtWidgets
                
                
                @dataclass
                class Todo:
                    date: QtCore.QDate
                    name: str
                
                
                class TodoCalendar(QtWidgets.QCalendarWidget):
                    def __init__(self, list_of_events, *args, **kwargs):
                        super().__init__(*args, **kwargs)
                        self.list_of_events = list_of_events
                
                        self.table = self.findChild(QtWidgets.QTableView)
                        self.table.viewport().installEventFilter(self)
                
                    def paintCell(self, painter, rect, date):
                        super().paintCell(painter, rect, date)
                        for event in self.list_of_events:
                            if event.date == date:
                                painter.setBrush(QtCore.Qt.red)
                                painter.drawEllipse(rect.topLeft() + QtCore.QPoint(12, 7), 3, 3)
                
                    def eventFilter(self, source, event):
                        if (
                            event.type() == QtCore.QEvent.MouseButtonDblClick
                            and source is self.table.viewport()
                        ):
                            index = self.table.indexAt(event.pos())
                            date = self.dateForCell(index.row(), index.column())
                            today_events = [ev for ev in self.list_of_events if ev.date == date]
                            if today_events:
                                print(today_events)
                        return super().eventFilter(source, event)
                
                    def referenceDate(self):
                        refDay = 1
                        while refDay <= 31:
                            refDate = QtCore.QDate(self.yearShown(), self.monthShown(), refDay)
                            if refDate.isValid():
                                return refDate
                            refDay += 1
                        return QtCore.QDate()
                
                    @property
                    def firstColumn(self):
                        return (
                            1
                            if self.verticalHeaderFormat() == QtWidgets.QCalendarWidget.ISOWeekNumbers
                            else 0
                        )
                
                    @property
                    def firstRow(self):
                        return (
                            0
                            if self.horizontalHeaderFormat()
                            == QtWidgets.QCalendarWidget.NoHorizontalHeader
                            else 1
                        )
                
                    def columnForDayOfWeek(self, day):
                        if day < 1 or day > 7:
                            return -1
                        column = day - self.firstDayOfWeek()
                        if column < 0:
                            column += 7
                        return column + self.firstColumn
                
                    def columnForFirstOfMonth(self, date):
                        return (self.columnForDayOfWeek(date.dayOfWeek()) - (date.day() % 7) + 8) % 7
                
                    def dateForCell(self, row, column):
                        if (
                            row < self.firstRow
                            or row > (self.firstRow + 6 - 1)
                            or column < self.firstColumn
                            or column > (self.firstColumn + 7 - 1)
                        ):
                            return QtCore.QDate()
                        refDate = self.referenceDate()
                        if not refDate.isValid():
                            return QtCore.QDate()
                        columnForFirstOfShownMonth = self.columnForFirstOfMonth(refDate)
                        if columnForFirstOfShownMonth - self.firstColumn < 1:
                            row -= 1
                        requestedDay = (
                            7 * (row - self.firstRow)
                            + column
                            - columnForFirstOfShownMonth
                            - refDate.day()
                            + 1
                        )
                        return refDate.addDays(requestedDay)
                
                
                if __name__ == "__main__":
                    import sys
                
                    app = QtWidgets.QApplication(sys.argv)
                
                    events = [
                        Todo(QtCore.QDate.currentDate().addDays(random.randint(1, 10)), f"name-{i}")
                        for i in range(15)
                    ]
                
                    w = TodoCalendar(events)
                    w.show()
                    sys.exit(app.exec_())
                

                這篇關于在 QCalendarWidget 中將項目添加到 QTableView的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                How to bind a function to an Action from Qt menubar?(如何將函數綁定到 Qt 菜單欄中的操作?)
                PyQt progress jumps to 100% after it starts(PyQt 啟動后進度躍升至 100%)
                How to set yaxis tick label in a fixed position so that when i scroll left or right the yaxis tick label should be visible?(如何將 yaxis 刻度標簽設置在固定位置,以便當我向左或向右滾動時,yaxis 刻度標簽應該可見
                `QImage` constructor has unknown keyword `data`(`QImage` 構造函數有未知關鍵字 `data`)
                Change x-axis ticks to custom strings(將 x 軸刻度更改為自定義字符串)
                How to show progress bar while saving file to excel in python?(如何在python中將文件保存為excel時顯示進度條?)

                        <tbody id='Pv8wR'></tbody>
                    • <legend id='Pv8wR'><style id='Pv8wR'><dir id='Pv8wR'><q id='Pv8wR'></q></dir></style></legend>

                      <small id='Pv8wR'></small><noframes id='Pv8wR'>

                      <tfoot id='Pv8wR'></tfoot>
                    • <i id='Pv8wR'><tr id='Pv8wR'><dt id='Pv8wR'><q id='Pv8wR'><span id='Pv8wR'><b id='Pv8wR'><form id='Pv8wR'><ins id='Pv8wR'></ins><ul id='Pv8wR'></ul><sub id='Pv8wR'></sub></form><legend id='Pv8wR'></legend><bdo id='Pv8wR'><pre id='Pv8wR'><center id='Pv8wR'></center></pre></bdo></b><th id='Pv8wR'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Pv8wR'><tfoot id='Pv8wR'></tfoot><dl id='Pv8wR'><fieldset id='Pv8wR'></fieldset></dl></div>
                        <bdo id='Pv8wR'></bdo><ul id='Pv8wR'></ul>

                        1. 主站蜘蛛池模板: 五月天婷婷激情 | 91极品视频 | 精品国产鲁一鲁一区二区张丽 | 精品国产一区二区三区久久久四川 | 久久高清国产 | 久久精品成人 | 综合久久99| 午夜99| 一区二区三区欧美 | 精品免费国产视频 | 精品中文字幕一区 | www.五月天婷婷.com | 欧美在线小视频 | www.99精品 | 中午字幕在线观看 | 91麻豆久久久 | 日韩中文字幕一区 | 欧美高清视频在线观看 | 在线观看黄色 | 久久国产精品精品国产色婷婷 | 婷婷狠狠| 日本久久久影视 | 久久免费大片 | 欧美久久一级特黄毛片 | 精品一区二区三 | 中文字幕一区二区三区四区 | 久久综合九色综合欧美狠狠 | 国产精品完整版 | 做a视频 | 成人免费观看男女羞羞视频 | 欧美精品一区二区三区在线四季 | 日本免费一区二区三区 | 欧美中文字幕一区二区三区亚洲 | 日韩精品一区二区三区视频播放 | 欧美人人| 午夜视频免费在线观看 | 一区二区三区四区不卡视频 | 香蕉久久a毛片 | 浴室洗澡偷拍一区二区 | 精品福利视频一区二区三区 | 久久久久国产精品一区 |