How to Develop a Calendar Widget.



  • Hello Friends,I want to develop a full fledged calendar, so that i can interact with the dates, set reminders on specified date, One idea, in my mind is, to take separate buttons for all the dates, but if do like that what about the default calendar widget already present in the qt designer, can't we use that directly... please help me out..

    Regards
    imrrk



  • That is not a simple challenge. You can look at the way the calendar widget is implemented for inspiration. You will have to do lots of rendering of your own. You can use any of the tree approaches Qt offers for that: rendering widgets with QPaintEvent, using QGraphicsView items or even using QML.



  • You can have a look at "qt-apps.org":http://qt-apps.org/content/show.php/running?content=91023 there are some implementations of calendars.

    I'm sure there are more (perhaps in KDE, or some commercial solutions).



  • Using QML for UI will be much better I think, but then this will limit your application for 5th Edition devices and above only.



  • ok andre,my problem is that,i want to call some functions when a user clicks on the specified date..suppose a calendar is displaying a month of april,then when i select a specified date,i want to set some appointments or some remnders,how to do that..



  • Hello Qtk,I want to interact with the dates



  • Did you look at the examples at qt-apps?
    They have a full featured calender app, so they also handle clicks.
    If you implement it with model/view and also have a custom view, you can handle clicks.

    where is the problem?



  • hi gerolf,can specify which example to look at..because i found many



  • hey gerolf,i m not getting you...



  • imrrk: this is not a chat channel. Please use the edit link to the right of each message to add to a message; don't just post new ones all the time.

    On topic: I found that good calendar examples are hard to come by. I found a nice one (via a tip earlier in this forum, search the forum for calendar and you will find the topic), but that one I ended up getting send directly from the author. I have not seen it published in the open again yet.



  • The link I provided was one app at qt-apps. But if you find more, have a look at them, if they look like what yu need, look at the source.



  • I just recently create a minimal calendar in QtQuick in Javascript. It is unfinished, but shows dates correctly;)

    https://github.com/unclefrank/weekly



  • hi gerolf,I got about the application you are speaking about,,is it applicable to mobile phones..also



  • [quote author="imrrk" date="1302167524"]hi gerolf,I got about the application you are speaking about,,is it applicable to mobile phones..also

    [/quote]
    Try and see?



  • Thanks andre...



  • hello friends,still i dint get any concrete material so that i can develop a calendar for mobile..actually i want to use pushbuttons,for dates i.e very date is on pushbutton..so that i can click this button and i can add some notes for that button...but with the inbuilt widget its not possible i guess,because they have used QTableformat class and divided it into rows and columns..so friends please help me out..

    regards
    imrrk



  • If you have no existing code that works for you, start build it on your own. I have never seen a calendar build on buttons.

    We can give you ideas, suggestions for specific technical stuff. But we don't write your code. If you want it with buttons, sit down, take QtCreator and start coding.



  • but gerolf i just need the correct direction,have u seen the calendar of nokia phones..it has that feature...



  • First: why do you think you need buttons? You can of course implement a calendar based on grid of buttons. I am just wondering how that would help you achieve your goals?



  • That you click on a button?
    Or that you click on a date and something happens?

    You can use a model/view (like Qt calendar widget) and react on the mouse events. No buttons needed. Qt has no build in "button calendar". and if you need one, build it. Or try if you can get the code for the nokia phone calendar.



  • hello gerolf,as u said,I need something should happen when i click on date..please guide me..



  • QCalendarWidget provides that already. See the signals listed in the documentation for that class.



  • [quote author="imrrk" date="1302259716"]hello gerolf,as u said,I need something should happen when i click on date..please guide me..[/quote]

    If you derive from, a view and can handle mouse events, clicks should be easy... (they are mouse events). Read a bit of Qt documentation on events (QWidget etc.) and views.

    Or look at QCalendarWidget and its interface. Perhaps derive from that.



  • ok thanks gerolf,hey i have created a two dimensional array of buttons,i.e 6 rows and 7 col,and by taking a counter i have my dates on pushbutttons,now the remaining work is to change the values on these buttons as the month and year changes..so any suggestions...

    thanks
    imrrk



  • Yes. As others have said many times already, take a look at how other calendar widgets are implemented. There is one right in Qt already. Use your favourite text editor/IDE/pager to look at the source code for QCalendarWidget and see how they solved the problem.

    We are not here to write your code or do research for you. We are just a bunch of volunteers. We can help you out with specific technical problems but you have not shown what approaches you have tried to solve this problem yourself first.



  • hi zapB,I have reffered to inbuilt example only and tried to do it in designer instead of hardcoding and wasting time,so what i have done has been mentioned already above,,,



  • hi gerolf,i am reading as per ur instructions,I have one doubt,we know that we have default calendar widget in qt designer which we can drag and drop on the form,whether your suggestion applies to this inbuit widget too..



  • I was referring to how the dates and days of week are calculated not on how to do the actual drawing overall.



  • i have reffered and know the logic,just want to do it in different way,hey can u tell me the default qcalendar widget in deesigner can be used in a efficient way..



  • What do you mean by "efficient way"? Just drop it on your form and hook up to it's signals. I am not clear exactly what you are trying to achieve. Do you have a graphic mockup of what you are after and a list of features?



  • Hi imrrk,

    as already told many times, and now last time:

    make a derived class for what you described. Make a

    @
    class MyCalendarWidget : public QCalendarWidget
    @

    there change the mouse handling, change the drawing and you have what you need.
    Then build up your UI on top of that.



  • [quote author="imrrk" date="1302268936"]i have reffered and know the logic,just want to do it in different way,hey can u tell me the default qcalendar widget in deesigner can be used in a efficient way..[/quote]

    How should we know if it fits your needs? What a strange question...

    How about just getting your hands dirty and trying it? In the time you wrote all this comments you could have ended up with a prototype showcase.



  • Hello friends,
    I have taken an taken an inbuilt QCalendarwidget and written a slot ,here when i click on dates i get the same date on the textbrowser.below is my code.
    dialog.cpp

    @#include "dialog.h"
    #include "ui_dialog.h"
    #include<QCalendarWidget>
    #include<QDate>

    Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
    {
    ui->setupUi(this);
    QCalendarWidget *cal=new QCalendarWidget();
    cal->setDateEditEnabled(1);
    cal->setFirstDayOfWeek(Qt::Wednesday);

    cal->show();
    }

    Dialog::~Dialog()
    {
    delete ui;
    }

    void Dialog::on_calendarWidget_clicked(QDate date)
    {
    ui->textBrowser->setText(date.toString());

    }

    @
    i know its simple,but i want to know whether in a similar way,we can open a new dialog on clicking a date....?



  • Sure. In your on_calendarWidget_clicked(QDate date), you do something like this:

    @
    void Dialog::on_calendarWidget_clicked(QDate date)
    {
    MyFancyDialog dlg(this); // MyFancyDialog is derived from QDialog
    dlg.setDateToWorkWith(date); // I guess the dialog needs to do something with the date
    if (dlg.exec() == QDialog::Accepted) { // this will make the dialog modal

        //now do something with the results
        //you can give MyFancyDialog member functions to access the resulting data
    }
    

    }
    @



  • hi andre,
    i opened a new dialog with the below code:
    @void Dialog::on_calendarWidget_clicked(QDate date)
    {
    Dialog1 a(this);
    a.show();
    a.exec();
    }@
    hey
    dlg.setDateToWorkWith(Date).whether its in built function?,because i didnt find it..

    and one more thing ,i want to know can we change the color of cells ?



  • You have to write your own custom dialog that inherits QDialog. How on earth is Qt supposed to ship a dialog already tailored to your precise needs? Andre just made that function name up as an example.



  • [quote author="imrrk" date="1302591858"]hi andre,
    i opened a new dialog with the below code:
    @void Dialog::on_calendarWidget_clicked(QDate date)
    {
    Dialog1 a(this);
    a.show();
    a.exec();
    }@
    hey
    dlg.setDateToWorkWith(Date).whether its in built function?,because i didnt find it..[/quote]
    Eh, what do you think? I make up an obviously fake dialog name with an obviously fake method name, and you expect that to be in Qt by default. And what should that method do then, exactly? Also: there is no need to call both show() and exec(). Either one will suffice.
    [quote]
    and one more thing ,i want to know can we change the color of cells ?[/quote]
    You mean of your calendar widget, right? Perhaps you could read the documentation of the QCalendarWidget? I just did, and found what you need in less than ten seconds.



  • Hello Andre,you r really mistaken,I didnt say that u r fake dialog name should work,I know that,its just an example to understand,I was just asking about the setDateToWorkwith(Date) thats it..
    and its great that you have found out it in tensecs..I will also try and will get back to you..

    Thanks
    imrrk



  • Problem is, you did not say what you would like to use the date for in your dialog, so how should we know how that method should look? Let alone, how would the Qt developers a couple of years ago have known?

    It could be as simple as this:
    @
    void MyFancyDialog::setDateToWorkWith(QDate date) //you might want to think of a better name than this...
    {
    //m_ui is a member pointer to your UI class instance
    //your .ui has a QLabel on it called "dateLabel"
    m_ui->dateLabel->setText(date.toString(Qt::SystemLocaleLongDate));
    }
    @

    But perhaps your dialog has to do something way more fancy with the date than that. Since you did not tell us, it is hard to give a better example.



  • Ok,andre I apologize for that,but andre,my question of concern is that,suppose I will give one example here,suppose in a month of 30 or 31 or 28 days ,suppose it will rain on 5 days,and other 5 days it will be hot,another 5 days it will be very cold ,,,and so..on..So suppose the user selects one of the date and he wants to know the above statics,then what should happen is that,all the above climatic conditions should be represnted as different colors on date,the colors should get set on dates depending on the climatic condition...i.e is rain-blue,hot-red,cold-green and so on..so whether this is possible..

    thanks
    imrrk


Log in to reply
 

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