logo
Tags down

shadow

How to disable other months days in QCalendarWidget


By : Maklak
Date : October 15 2020, 08:10 PM
I wish this helpful for you One solution is to filter the mousePressEvent event of the QTableView that the QCalendarWidget has Internally. For this we use the event filter:
code :
from PyQt5 import QtCore, QtWidgets

class CalendarWidget(QtWidgets.QCalendarWidget):
    def __init__(self, parent=None):
        super(CalendarWidget, self).__init__(parent, gridVisible=False,
            horizontalHeaderFormat=QtWidgets.QCalendarWidget.SingleLetterDayNames,
            verticalHeaderFormat=QtWidgets.QCalendarWidget.NoVerticalHeader,
            navigationBarVisible=True,
            dateEditEnabled=True)       
        self.setEnabled(True)
        self.setGeometry(QtCore.QRect(0, 0, 320, 250))
        self.clicked.connect(print)

        self.table_view = self.findChild(QtWidgets.QTableView, "qt_calendar_calendarview")
        self.table_view.viewport().installEventFilter(self)
        self.setFirstDayOfWeek(QtCore.Qt.Monday)

    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()

    def columnForDayOfWeek(self, day):
        m_firstColumn = 1 if self.verticalHeaderFormat() != QtWidgets.QCalendarWidget.NoVerticalHeader else 0
        if day < 1 or day > 7: return -1
        column = day - int(self.firstDayOfWeek())
        if column < 0:
            column += 7
        return column + m_firstColumn

    def columnForFirstOfMonth(self, date):
        return (self.columnForDayOfWeek(date.dayOfWeek()) - (date.day() % 7) + 8) % 7

    def dateForCell(self, row, column):
        m_firstRow = 1 if self.horizontalHeaderFormat() != QtWidgets.QCalendarWidget.NoHorizontalHeader else 0
        m_firstColumn = 1 if self.verticalHeaderFormat() != QtWidgets.QCalendarWidget.NoVerticalHeader else 0
        rowCount = 6
        columnCount = 7
        if row < m_firstRow or row > (m_firstRow + rowCount -1) or column < m_firstColumn or column > (m_firstColumn + columnCount -1):
            return QtCore.QDate()
        refDate = self.referenceDate()
        if not refDate.isValid():
            return QtCore.QDate()
        columnForFirstOfShownMonth = self.columnForFirstOfMonth(refDate)
        if (columnForFirstOfShownMonth - m_firstColumn) < 1:
            row -= 1
        requestedDay = 7*(row - m_firstRow) +  column  - columnForFirstOfShownMonth - refDate.day() + 1
        return refDate.addDays(requestedDay)

    def eventFilter(self, obj, event):
        if obj is self.table_view.viewport() and event.type() == QtCore.QEvent.MouseButtonPress:    
            ix = self.table_view.indexAt(event.pos())
            date = self.dateForCell(ix.row(), ix.column())
            d_start = QtCore.QDate(self.yearShown(), self.monthShown(), 1)
            d_end = QtCore.QDate(self.yearShown(), self.monthShown(), d_start.daysInMonth())
            if d_start > date or date > d_end:
                return True
        return super(CalendarWidget, self).eventFilter(obj, event)

    def paintCell(self, painter, rect, date):
        d_start = QtCore.QDate(self.yearShown(), self.monthShown(), 1)
        d_end = QtCore.QDate(self.yearShown(), self.monthShown(), d_start.daysInMonth())
        if d_start <= date <= d_end:
            super(CalendarWidget, self).paintCell(painter, rect, date)

if __name__ == '__main__':
    import sys
    app = QtWidgets.QApplication(sys.argv)
    w = CalendarWidget()
    w.show()
    sys.exit(app.exec_())


Share : facebook icon twitter icon

Disable days when change months


By : David
Date : March 29 2020, 07:55 AM
Any of those help This answer is a summary in partly pseudo code when all the comments on the question would be interpreted and worked with. It could contain typos, wrong classes but the intention is what counts now. Maybe I'll improve it later
xhtml:
code :
<p:calendar...>
    <p:ajax event="viewChange" listener="#{bean.myViewAction}" update="scriptPanel" />
</p:calendar>

<h:panelGroup id="scriptPanel">
    <script>
        function disableDays(date) {
            var datesToDisable = #{bean.disableDates};
            var month = date.getMonth(), day = date.getDate(), annio = date.getFullYear();
            for (i = 0; i < datesToDisable.length; i++) {
                if ($.inArray((month + 1) + '-' + day + '-' + annio, datesToDisable) != -1) {
                    return [ false ];
                }
            }
            return [ true ];
        }
    </script>
</h:panelGroup>
public void viewChange(DateViewChangeEvent e) { 
    // Get relvant info from event
    // determine new disableDates and set those in the correct formatted string
}

public void getDisableDates() {
    return disableDates;
}

Disable tooltip only for months and days in Highcharts


By : user7245025
Date : March 29 2020, 07:55 AM
may help you . If by "tick in my horizontal bar chart," you mean the axis labels, you could add the following to your xAxis options:
code :
labels: {
    formatter: function () {
        return Highcharts.dateFormat('%H:%M:%S', this.value);
    },
},
tooltip: {
    formatter: function () {
        return Highcharts.dateFormat('%H:%M:%S', this.x);
    },
},

JqueryUi DatePicker - Disable days in different months


By : Sai Balaji
Date : March 29 2020, 07:55 AM
may help you . your code in the jsfiddle actually works, the issue is actually just that the dates at the beginning of december don't have leading zero's . So the quickest solution is to just take the leading 0 off.
Working Fiddle: https://jsfiddle.net/b73bmn3e/6/
code :
var arrayDaysToshow = ["30-11-2017", "01-12-2017", "02-12-2017"];
var arrayDaysToshow = ["30-11-2017", "1-12-2017", "2-12-2017"];

VBA: Userform Error date values change - months as days and days as months


By : JoseLopez
Date : March 29 2020, 07:55 AM
With these it helps I'm using this calendar in my userform to enter dates in Textbox1. It works fine within the userform (format "dd/mm/yyyy") - no problem either filling dates directly to an active cell. , Use CDate to convert the text to a real date value:
code :
ws.Cells(MyNR, 14).Value = CDate(TextBox1.value)
ws.Cells(MyNR, 15).Value = CDate(TextBox2.value)

Get difference of 2 dates in years, months, days, but answer is always off by a couple days/months


By : user2540426
Date : March 29 2020, 07:55 AM
it should still fix some issue A year does not always have 365 days. Compared to the web site you refer to, there is also another difference:
Usually when people speak of "today it is exactly 1 month ago", they mean it was on the same month-date. So 14 March comes exactly 1 month after 14 February, and 14 April comes exactly 1 month after 14 March. This means the length of what a "month" is, depends on what your reference point is. In the example, the first difference is 28 days (in non-leap years), while the second is 31 days.
code :
function dateDiff(a, b) {
    // Some utility functions:
    const getSecs = dt => (dt.getHours() * 24 + dt.getMinutes()) * 60 + dt.getSeconds();
    const getMonths = dt => dt.getFullYear() * 12 + dt.getMonth();

    // 0. Convert to new date objects to avoid side effects
    a = new Date(a);
    b = new Date(b);
    if (a > b) [a, b] = [b, a]; // Swap into order 
    
    // 1. Get difference in number of seconds during the day:
    let diff = getSecs(b) - getSecs(a);
    if (diff < 0) {
        b.setDate(b.getDate()-1); // go back one day
        diff += 24*60*60; // compensate with the equivalent of one day
    }
    // 2. Get difference in number of days of the month
    let days = b.getDate() - a.getDate();
    if (days < 0) {
        b.setDate(0); // go back to (last day of) previous month
        days += b.getDate(); // compensate with the equivalent of one month
    }
    // 3. Get difference in number of months
    const months = getMonths(b) - getMonths(a); 
    return {
        years: Math.floor(months/12),
        months: months % 12,
        days, 
        hours: Math.floor(diff/3600),
        minutes: Math.floor(diff/60) % 24,
        seconds: diff % 60
    };
}

// Date to start on
var startDate = new Date("Jun 5, 2011 00:00:00");

// Update the count every 1 second
setInterval(function() {
    const diff = dateDiff(startDate, new Date);
    const str = Object.entries(diff).map(([name, value]) =>
        value > 1 ? value + " " + name : value ? value + " " + name.slice(0, name.length-1) : ""
    ).filter(Boolean).join(", ") || "0 seconds";  
    document.getElementById("demo").textContent = str;
}, 1000); 
<div id="demo"></div>
Related Posts Related Posts :
  • How to add result of previous row to contents of present row?
  • Train LSTM with probabilistic labels
  • AWS Cloudwatch Logstream - What is the key, and how can I set it when getting the logstream
  • Page Pagination/Scraping with Requests/BeautifulSoup
  • How to fix NoReverseMatch on redirect
  • Using a list to name output files in Arcpy
  • Need help conditionally vectorizing a list
  • I want to apply a threshold to pixels in image using python. Where did I make a mistake?
  • Problems unsing Beautiful Soup
  • python binning data openAI gym
  • Python: Argparse with list of lists
  • Creating Columns in m x 1 dataframe based on spaces in each row?
  • Explicit relative imports within a package not using the keyword from
  • APScheduler and passing arguments
  • Compare two lists and print out when a change happens
  • Decoding Django POST request body
  • How to fill pandas dataframe columns in for loop
  • Keras backend function: InvalidArgumentError
  • Get index of elements in first Series within the second series
  • Redirecting to a new URL to parse through
  • Transform string into a bit array
  • How to print list one after the other in a vertical order in text file in python
  • Python divide each string by the total lenght of string
  • Pymongo Bulk Delete
  • Python / NiFi: ExecuteScript python, to convert an UTF-16 text files to UTF-8
  • Getting l1 normalized eigenvectors from python instead of l2?
  • Get span inside a class using WebDriver and Selenium
  • Non blocking command process
  • I'm getting positional argument in Django rest framework APIView class empty. Why? And how to pass value into it?
  • Create an array according to index in another array in Python
  • Matplotlib multiple Y-axes, xlabels disappear?
  • feedparser for reddit returning empty
  • physical dimensions and array dimensions
  • can't get my program to return to main loop
  • how to read image into tensor from url directly
  • Can't find a combination of keywords on an xml page using python and beautiful soup
  • Find the rotation of a quad (4 points, planar)
  • Class method input variables
  • Pandas Dataframe, how to group columns together in Python
  • What does "auth.User" in Django do?
  • Python - Get Last Element after str.split()
  • How to access a variable in one python function in another function
  • Manually computed validation loss different from reported val_loss when using regularization
  • Filtering with a only one conditional
  • How to set specific faker random string of specific length and using underscores for spaces?
  • seaborn FacetGrid+map_dataframe fails (but not when using map)
  • How to get GraphQL schema with Python?
  • Python - How to send values between functions once
  • Loop sum find and multiple
  • Map & append multiple values (per each key) from a dict to different columns of a dataframe
  • Python list of dictionaries incrementation error
  • Filtering Spark Dataframe
  • pytest: How to test project-dependent directory creation?
  • Python Group by and Sum with a Blank space
  • Reorder and return the whole of nested dictionary
  • Finding element from one list in nested second list
  • Calculating AUC for Unsupervised LOF in sklearn
  • Storing Specific Whole Numbers - Python
  • Simulate SHL and SHR ASM instructions in Python
  • AttributeError: type object 'DirectView' has no attribute 'as_view'
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org