Put a png image as cells backgrounds in a QCalendarWidget



  • I Need to put a different image as background for each monthly day in a QCalendarWidget, these images are in a resources.qrc file and are named as img_000.png to img_030.png and will be changed according the respective month and day, this mechanism for get the images is ok and working, but I don't know how to change the cell background of a QCalendarWidget.
    At this moment I have done the calendar and changed it to attend my necessity, but I need to put these image as background.

    Someone can help-me?

    Thanks in advance!


  • Qt Champions 2016

    @marquessbr

    Hi did you subclass QCalendarWidget ?

    As far as i know, you can change whole background with stylesheet
    So when change month yo umight be able to change stylesheet and get image
    but i never tested this.

    http://www.qtcentre.org/threads/30478-How-To-Change-Style-Sheet-for-QCalendarWidget



  • @mrjj

    Hi mrjj I got a calendar like I want using qml+javascript to get the images, it is working, but as Iam completely newbie in qt so, I stop it because I don't know how to connect this calendar with my cpp code, so what I need is to know how I can put this calendar:
    alt text
    made using qml into my QCalendarWidget constructor in my cpp file, and then connect its my own navbar to correspond to the calendarwidget navbar, e.g.: the minus and plus button increment and decrement month, the "<" and ">" increment and decrement day and toggle the minus button pressed, appear a menu with more date options, and the textEdit or label show the new selected date as "mm/dd/yyyy" format.

    It is all for now.


  • Moderators

    @marquessbr You can embed QML in widget using http://doc.qt.io/qt-5/qquickwidget.html



  • @jsulm

    Hi, jsulm, in the qt examples set I see "QGuiApplication" and "QQmlApplicationEngine", these are the same or your effects is equal or similar of QQuickWidget?

    thanks!


  • Moderators

    @marquessbr said in Put a png image as cells backgrounds in a QCalendarWidget:

    QQmlApplicationEngine

    If I understand you correctly you want to write a widget application but embed this QML calendar, right? If so then QGuiApplication is what you need.



  • @jsulm Yes its just it, it is very complicated for me: java programmer, so I will try here and when I conclude I mark the post solved, it's ok?

    thanks!

    PS.: @jsulm, im as I said, I start creating it using qml, but when I try to connect the buttons to they respective actions, I got difficult, so I try to implement it using widget, but later, I see which is possible to embed qml into c++ code.



  • @jsulm

    Hi my friend!

    I got it working here, at last I can made the buttons of my custom navigation bar working, but now I need to know how I can made the calendar to reflect the changes of the buttons, so I have the qml code: https://pastebin.com/GcT6S47B
    As I got this working, maybe I can solve this thread and post a new Question, as I say Iam newbie in qt and in this forum also.

    thanks



  • Now it is working here, I connect the buttons action to the calendar using:

                                currentDate.setFullYear(aNewYear, aNewMonth, aNewDay);
                                calendar.selectedDate = new Date(aNewYear, aNewMonth, aNewDay);
                                calendar.update();
    

    Now I have a calendar and a custom navigation bar

    thanks for all!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.