Not able to select QCalendarWidget popup when try

2020-05-01 05:01发布

I have a python file (file1.py) which have a button and when pressed it will popup calender widget. Once the date selected in Calender widget, it will displayed in Qlineedit box(Object Name : Delivery_date_le). This functionality working as expected when run the file1.py alone.

I have a Mainwindow file (Main.py) where it have menu button to call file1.py window. when accessing the file1 window from main.py, the window opened but selecting the calender widget popup not happening (not able to select the date). Please help me on this.

file1.py:

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QDialog,QCalendarWidget,QMessageBox
from PyQt5.QtCore import QDate,Qt
import os
import pyodbc
import datetime
class Ui_Daily_bill(object):
    def setupUi(self, Daily_bill):
        Daily_bill.setObjectName("Daily_bill")
        Daily_bill.resize(1215, 809)
        self.cal_tool_btn = QtWidgets.QToolButton(Daily_bill)
        self.cal_tool_btn.setGeometry(QtCore.QRect(1159, 97, 30, 32))
        self.cal_tool_btn.setStyleSheet("background-color: rgb(255, 255, 255);")
        self.cal_tool_btn.setText("")
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("images/calendar-512.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.cal_tool_btn.setIcon(icon)
        self.cal_tool_btn.setIconSize(QtCore.QSize(30, 30))
        self.cal_tool_btn.setObjectName("cal_tool_btn")
        self.delivery_date_le = QtWidgets.QLineEdit(Daily_bill)
        self.delivery_date_le.setGeometry(QtCore.QRect(919, 98, 241, 31))
        font = QtGui.QFont()
        font.setFamily("Calibri")
        font.setPointSize(12)
        font.setBold(True)
        font.setWeight(75)
        self.delivery_date_le.setFont(font)
        self.delivery_date_le.setObjectName("delivery_date_le")
    def retranslateUi(self, Daily_bill):
        _translate = QtCore.QCoreApplication.translate
        Daily_bill.setWindowTitle(_translate("Daily_bill", "Dialog"))


class Add_Daily_Bill(QDialog,Ui_Daily_bill):
    def __init__(self,parent=None):
        super(Add_Daily_Bill,self).__init__(parent)
        self.setupUi(self)
        self.cal_tool_btn.clicked.connect(self.delivery_calender)

    def delivery_calender(self):
        self.calender = QCalendarWidget()
        self.calender.setMinimumDate(QDate(1900,1,1))
        self.calender.setMaximumDate(QDate(2999,12,31))
        self.calender.setGridVisible(True)
        self.calender.clicked.connect(self.updatedate)

        self.calender.show()


    def updatedate(self,*args):

        getdate = self.calender.selectedDate().toString("dd/MM/yyyy")
        print('get date value is ',getdate)
        self.delivery_date_le.setText(getdate)
        self.calender.deleteLater()


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    Daily_bill = QtWidgets.QDialog()
    #ui = Ui_Daily_bill()
    #ui.setupUi(Daily_bill)
    #Daily_bill.show()
    ui = Add_Daily_Bill()
    ui.show()
    sys.exit(app.exec_())

Main.py

from PyQt5.QtWidgets import QApplication,QMainWindow,QAction, QMessageBox,QLabel,QVBoxLayout, QWidget,QDialog
from PyQt5 import QtGui
from PyQt5.QtGui import QPixmap
from file1 import Add_Daily_Bill
import sys

class Mainwindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.windowpage()

    def windowpage(self):

        menubar = self.menuBar()

        custbillmenu = menubar.addMenu('Customer Billing')
        dailybill = QAction('Daily Bill',self)
        custbillmenu.addAction(dailybill)
        dailybill.triggered.connect(self.daily_bill)

    def daily_bill(self):
        dialog =Add_Daily_Bill()
        dialog.exec_()

if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = Mainwindow()
    window.showMaximized()
    sys.exit(app.exec_())

0条回答
登录 后发表回答