Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QCalendarWidget Set day name manually



  • I am trying to set each of the daynames on the horizontal header of the QCalendarWidget manually. I was able to do this with the month names in the month menu by accessing each of the QActions and setting its text to what I wanted. I want to do the same for the day names, such as Mon, Tue, etc to something fictional. How can I do this?


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    AFAIK, there's no easy way for that. QCalendarWidget uses a custom model that relies on the locale to provide the name of the day.



  • @basimchowdhury
    Can you not use setLocale() to achieve what you desire for both month & day names?



  • @JonB I am aware if setLocale() but what I need to do is set the names of the day to anything else, even a made up language for example. Isnt there a way to access the text being set in the header and set it manually using setText() or something like that?



  • @basimchowdhury
    Well you & I are not finding such a setText(), and @SGaist posted at the same time as I was composing my reply stating

    AFAIK, there's no easy way for that. QCalendarWidget uses a custom model that relies on the locale to provide the name of the day.

    Hence my suggestion, and I was also thinking you might be able to invent a "dummy" locale if you had to. Though quite why you want to change these names to something which isn't even in a locale I don't know! Unless you are deliberately wanting to confuse the user by e.g. showing "Wednesday" when it's "Tuesday" or "November" when it's "February" :)



  • @SGaist Is there a way to access the widget or the component that holds the text for the days so that I may manually set it using setText()? Again I was able to accomplish this with the month name by accessing the QMenu object attached to the month button and then getting the QList of QActions, each corresponding to a month, and manually calling setText() for each of them. I am looking for a similar solution.


Log in to reply