亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

QCalendarWidget 呈現小

QCalendarWidget 呈現小

繁星coding 2022-05-24 17:09:26
我正在嘗試使用,QCalendarWidget但它沒有按預期在用戶界面中呈現。我看到的示例顯示了一個類似于對象的日歷選擇器,但在我的情況下,我得到了一個非常小的字段渲染。這是它在 UI 中的樣子:這是我第一次使用它,所以我不確定我是否錯過了一個步驟。關于我可能做錯了什么有什么想法嗎?這是正在使用的完整代碼:from PyQt5.QtWidgets import QMainWindow, QCalendarWidget, QLabelfrom PyQt5 import QtCore, QtWidgets, QtGuiimport sysclass Example(QMainWindow):   def __init__(self):      super(Example, self).__init__()      self.initUI()   def initUI(self):      cal = QCalendarWidget(self)      cal.setGridVisible(True)      cal.move(20, 20)      cal.clicked[QtCore.QDate].connect(self.showDate)      self.lbl = QLabel(self)      date = cal.selectedDate()      self.lbl.setText(date.toString())      self.lbl.move(20, 200)      self.setGeometry(100,100,300,300)      self.setWindowTitle('Calendar')      self.show()   def showDate(self, date):      self.lbl.setText(date.toString())def main():    app = QtWidgets.QApplication(sys.argv)    mainWin = Example()    mainWin.show()    sys.exit( app.exec_() )if __name__ == '__main__':   main()
查看完整描述

1 回答

?
莫回無

TA貢獻1865條經驗 獲得超7個贊

在 QMainWindow 的 centralWidget 中使用布局,例如 QVBoxLayout:


import sys


from PyQt5 import QtCore, QtGui, QtWidgets 



class Example(QtWidgets.QMainWindow):

    def __init__(self):

        super(Example, self).__init__()


        self.initUI()


    def initUI(self):


        cal = QtWidgets.QCalendarWidget(gridVisible=True)

        cal.clicked.connect(self.showDate)


        self.lbl = QtWidgets.QLabel()

        date = cal.selectedDate()

        self.lbl.setText(date.toString())


        central_widget = QtWidgets.QWidget()

        self.setCentralWidget(central_widget)

        lay = QtWidgets.QVBoxLayout(central_widget)

        lay.addWidget(cal)

        lay.addWidget(self.lbl)


        self.setGeometry(100, 100, 300, 300)

        self.setWindowTitle("Calendar")


    @QtCore.pyqtSlot(QtCore.QDate)

    def showDate(self, date):

        self.lbl.setText(date.toString())



def main():


    app = QtWidgets.QApplication(sys.argv)

    mainWin = Example()

    mainWin.show()

    sys.exit(app.exec_())



if __name__ == "__main__":

    main()

http://img1.sycdn.imooc.com//628ca10200019e2304070324.jpg

查看完整回答
反對 回復 2022-05-24
  • 1 回答
  • 0 關注
  • 193 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號