Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to Develop a Calendar Widget.

How to Develop a Calendar Widget.

Scheduled Pinned Locked Moved Mobile and Embedded
119 Posts 11 Posters 82.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    ZapB
    wrote on 8 Apr 2011, 12:43 last edited by
    #25

    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.

    Nokia Certified Qt Specialist
    Interested in hearing about Qt related work

    1 Reply Last reply
    0
    • I Offline
      I Offline
      imrrk
      wrote on 8 Apr 2011, 13:04 last edited by
      #26

      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,,,

      1 Reply Last reply
      0
      • I Offline
        I Offline
        imrrk
        wrote on 8 Apr 2011, 13:07 last edited by
        #27

        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..

        1 Reply Last reply
        0
        • Z Offline
          Z Offline
          ZapB
          wrote on 8 Apr 2011, 13:12 last edited by
          #28

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

          Nokia Certified Qt Specialist
          Interested in hearing about Qt related work

          1 Reply Last reply
          0
          • I Offline
            I Offline
            imrrk
            wrote on 8 Apr 2011, 13:22 last edited by
            #29

            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..

            1 Reply Last reply
            0
            • Z Offline
              Z Offline
              ZapB
              wrote on 8 Apr 2011, 13:30 last edited by
              #30

              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?

              Nokia Certified Qt Specialist
              Interested in hearing about Qt related work

              1 Reply Last reply
              0
              • G Offline
                G Offline
                giesbert
                wrote on 8 Apr 2011, 13:38 last edited by
                #31

                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.

                Nokia Certified Qt Specialist.
                Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  goetz
                  wrote on 8 Apr 2011, 17:48 last edited by
                  #32

                  [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.

                  http://www.catb.org/~esr/faqs/smart-questions.html

                  1 Reply Last reply
                  0
                  • I Offline
                    I Offline
                    imrrk
                    wrote on 12 Apr 2011, 05:27 last edited by
                    #33

                    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....?

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      andre
                      wrote on 12 Apr 2011, 06:31 last edited by
                      #34

                      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
                      }
                      

                      }
                      @

                      1 Reply Last reply
                      0
                      • I Offline
                        I Offline
                        imrrk
                        wrote on 12 Apr 2011, 07:04 last edited by
                        #35

                        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 ?

                        1 Reply Last reply
                        0
                        • Z Offline
                          Z Offline
                          ZapB
                          wrote on 12 Apr 2011, 07:16 last edited by
                          #36

                          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.

                          Nokia Certified Qt Specialist
                          Interested in hearing about Qt related work

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            andre
                            wrote on 12 Apr 2011, 07:41 last edited by
                            #37

                            [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.

                            1 Reply Last reply
                            0
                            • I Offline
                              I Offline
                              imrrk
                              wrote on 12 Apr 2011, 08:51 last edited by
                              #38

                              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

                              1 Reply Last reply
                              0
                              • A Offline
                                A Offline
                                andre
                                wrote on 12 Apr 2011, 09:03 last edited by
                                #39

                                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.

                                1 Reply Last reply
                                0
                                • I Offline
                                  I Offline
                                  imrrk
                                  wrote on 12 Apr 2011, 09:30 last edited by
                                  #40

                                  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

                                  1 Reply Last reply
                                  0
                                  • A Offline
                                    A Offline
                                    andre
                                    wrote on 12 Apr 2011, 09:39 last edited by
                                    #41

                                    Yes, of course that is possible, but that is something different again than what you asked before about using a separate dialog, and what that dialog is supposed to do. Now, you are talking about styling the QCalendarWidget again. Did you take a look at the documentation of that class yet? Did you find out how you can style the display of a specific date?

                                    Edit:
                                    Just to proof that I am not bulshitting you about that this is perfectly possible with QCalendarWidget, I put this example together:

                                    !http://dl.dropbox.com/u/16442531/coloredCalendar.png(Colored calendar example)!

                                    This is what you were after, right?

                                    1 Reply Last reply
                                    0
                                    • G Offline
                                      G Offline
                                      giesbert
                                      wrote on 12 Apr 2011, 09:43 last edited by
                                      #42

                                      Hi imrrk,

                                      that is all up to you and your application.
                                      You asked about how to handle the click on a calendar date and how to open a dialog. You got the answers. We will not write your application. A little bit is also up to you.

                                      The general info on how to react on a calendar click and to open a dialog was given.

                                      Nokia Certified Qt Specialist.
                                      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                                      1 Reply Last reply
                                      0
                                      • Z Offline
                                        Z Offline
                                        ZapB
                                        wrote on 12 Apr 2011, 09:45 last edited by
                                        #43

                                        Maybe the best thing you could do would be to draw a mockup of what you are trying to achieve so that we can all see it. You seem to keep changing your mind every 3rd post or so.

                                        Nokia Certified Qt Specialist
                                        Interested in hearing about Qt related work

                                        1 Reply Last reply
                                        0
                                        • G Offline
                                          G Offline
                                          giesbert
                                          wrote on 12 Apr 2011, 09:46 last edited by
                                          #44

                                          [quote author="Andre" date="1302601186"]Yes, of course that is possible, but that is something different again than what is supposed to be in a separate dialog, and what that dialog is supposed to do. Now, you are talking about styling the QCalendarWidget again. Did you take a look at the documentation of that class yet? Did you find out how you can style the display of a specific date?[/quote]

                                          Styling the calndar items can only be done by subclassign QCalendarWidget and by overwriting

                                          • virtual void paintCell(QPainter* pPainter, const QRect& rCellRect, const QDate& rDate) const;

                                          Nokia Certified Qt Specialist.
                                          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                                          1 Reply Last reply
                                          0

                                          34/119

                                          12 Apr 2011, 06:31

                                          • Login

                                          • Login or register to search.
                                          34 out of 119
                                          • First post
                                            34/119
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved