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.
Forum Updated to NodeBB v4.3 + New Features

How to Develop a Calendar Widget.

Scheduled Pinned Locked Moved Mobile and Embedded
119 Posts 11 Posters 83.6k Views 1 Watching
  • 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.
  • I Offline
    I Offline
    imrrk
    wrote on last edited by
    #68

    actually dates colors are not cleared,when i click on the buttons..

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #69

      [quote author="Andre" date="1302698169"]Did you:

      • actually connect the signals with the slots?
      • check your output while running to see if the connection worked?
      • put debug statements or breakpoints at the relevant places to track what breaks down exactly?
        [/quote]
      1 Reply Last reply
      0
      • I Offline
        I Offline
        imrrk
        wrote on last edited by
        #70

        i will check it out and get back to u..thanks for your help

        1 Reply Last reply
        0
        • I Offline
          I Offline
          imrrk
          wrote on last edited by
          #71

          hwy volker i created two signals and i emitted them on click of push buttons,now in which dialog i should connect signals and which will be the sender and reciever ,I m not getting..

          regards
          imrrk

          1 Reply Last reply
          0
          • G Offline
            G Offline
            giesbert
            wrote on last edited by
            #72

            The sender of the signal is typically the object, that sends them, the receivedr is the object that implements the slots.

            so If you are inside the code of dlg1, which implements the slots and invoke there a dialog dlgh2 which emiuts the signals you do:

            @
            dlg1::foo()
            {
            dlg2 dlg;
            connect(&dlg, SIGNAL(fooSignal()), this, SLOT(fooSlot()));
            dlg.exec();
            }
            @

            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
            • I Offline
              I Offline
              imrrk
              wrote on last edited by
              #73

              hey gerolf in dialog1.cpp ,i have emmitted two signals on click of push buttons and connected them as shown below..I dont know whether i am correct in this,now I have my maindialog1.cpp where i wriiten the slots for setting colors,now I am not getting how shall i make connections with the signals i emmitted in dialog1.cpp and the slots in my maindialog.cpp,which contains the slots..

              @#include "dialog1.h"
              #include "ui_dialog1.h"
              #include<QCalendarWidget>
              Dialog1::Dialog1(QWidget *parent) :
              QDialog(parent),
              ui(new Ui::Dialog1)
              {
              ui->setupUi(this);
              connect(ui->set,SIGNAL(clicked()),this,SIGNAL(setclicked()));
              connect(ui->unset,SIGNAL(clicked()),this,SIGNAL(unsetclicked()));
              }

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

              void Dialog1::on_set_clicked()
              {
              emit setclicked();
              }

              void Dialog1::on_unset_clicked()
              {
              emit unsetclicked();
              }
              @
              this my dialog.cpp//
              @#include "dialog.h"
              #include "ui_dialog.h"
              #include<QCalendarWidget>
              #include<QDate>
              #include "dialog1.h"
              #include "ui_dialog1.h"
              #include<QPainter>
              #include <QtGui/QApplication>

              Dialog::Dialog(QWidget *parent) :
              QDialog(parent),
              ui(new Ui::Dialog)
              {
              ui->setupUi(this);
              //Dialog1 a(this);
              connect(&Dialog1,SIGNAL(setclicked(),this,SLOT(setcolors())));
              connect(&Dialog1,SIGNAL(unsetclicked(),this,SLOT(unsetcolors())));

              //   QCalendarWidget *cal=new QCalendarWidget();
              

              // cal->setDateEditEnabled(1);
              // cal->setFirstDayOfWeek(Qt::Wednesday);

              // cal->show();
              //ui->calendarWidget->setFirstDayOfWeek(Qt::Thursday);

              //QTextCharFormat colddate;
              //colddate.setBackground(Qt::yellow);

              //QTextCharFormat hotdate;
              //hotdate.setBackground(Qt::red);

              //QTextCharFormat wetdate;
              //wetdate.setBackground(Qt::green);

              //QTextCharFormat raindate;
              //raindate.setBackground(Qt::blue);

              //ui->calendarWidget->setDateTextFormat(QDate(2011,4,1),colddate);
              //ui->calendarWidget->setDateTextFormat(QDate(2011,4,5),hotdate);
              //ui->calendarWidget->setDateTextFormat(QDate(2011,4,8),wetdate);
              //ui->calendarWidget->setDateTextFormat(QDate(2011,4,9),raindate);
              //ui->calendarWidget->setDateTextFormat(QDate(2011,4,12),colddate);
              //ui->calendarWidget->setDateTextFormat(QDate(2011,4,14),hotdate);
              }

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

              void Dialog::on_calendarWidget_clicked(QDate date)
              {
              // ui->label->setText(date.toString());
              //ui->textBrowser->setText(date.toString());
              Dialog1 a(this);
              a.show();
              a.exec();

              // ui->pushButton->setText(QString::number(date.day()));

              }

              void Dialog::setcolors()
              {

              safedate.setBackground(Qt::green);
              //safedate.BackgroundImageUrl
              

              unsafedate.setBackground(Qt::yellow);

              fertiledate.setBackground(Qt::red);
              
              
              startdate.setBackground(Qt::blue);
              
              
              ui->calendarWidget->setDateTextFormat(QDate(2011,4,1),startdate);
              ui->calendarWidget->setDateTextFormat(QDate(2011,4,5),safedate);
              ui->calendarWidget->setDateTextFormat(QDate(2011,4,8),unsafedate);
              ui->calendarWidget->setDateTextFormat(QDate(2011,4,9),fertiledate);
              ui->calendarWidget->setDateTextFormat(QDate(2011,4,12),unsafedate);
              ui->calendarWidget->setDateTextFormat(QDate(2011,4,14),safedate);
              

              }

              void Dialog::unsetcolors()
              {
              startdate.clearBackground();
              safedate.clearBackground();
              unsafedate.clearBackground();
              fertiledate.clearBackground();
              ui->calendarWidget->setDateTextFormat(QDate(2011,4,1),startdate);
              ui->calendarWidget->setDateTextFormat(QDate(2011,4,5),safedate);
              ui->calendarWidget->setDateTextFormat(QDate(2011,4,8),unsafedate);
              ui->calendarWidget->setDateTextFormat(QDate(2011,4,9),fertiledate);
              ui->calendarWidget->setDateTextFormat(QDate(2011,4,12),unsafedate);
              ui->calendarWidget->setDateTextFormat(QDate(2011,4,14),safedate);
              }@

              regards
              imrrk

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #74

                In dialog.cpp, you need to make the connections not on lines 14 and 15, but where you actually create the dialog, after line 57. There you have a reference to both the dialogs, so there you make the connection.

                1 Reply Last reply
                0
                • I Offline
                  I Offline
                  imrrk
                  wrote on last edited by
                  #75

                  thanks andre ,I got it and its working fine,thanks a lot

                  1 Reply Last reply
                  0
                  • I Offline
                    I Offline
                    imrrk
                    wrote on last edited by
                    #76

                    hey andre as we have set the background colors for the cells can we set the backgroundimage for the cells...by using,

                    QTextcharformat date;
                    date.setbackgroundimageurl

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      giesbert
                      wrote on last edited by
                      #77

                      if this function exists, try it out.
                      have a look at the docs.

                      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
                      • A Offline
                        A Offline
                        andre
                        wrote on last edited by
                        #78

                        [quote author="imrrk" date="1302766931"]hey andre as we have set the background colors for the cells can we set the backgroundimage for the cells...by using,

                        QTextcharformat date;
                        date.setbackgroundimageurl[/quote]
                        Could you make your variable naming any more confusing? I mean: you're working with calendars and dates, and you call a variable that represents a text format date?

                        Anyway, QTextCharFormat (or its base class QTextFormat) does not have a method setBackgroundImageUrl. At least, not that I could find. But you can use a QBrush instead of a color, so that opens up some more options as brushes can be quite fancy... Check the documentation of QBrush.

                        1 Reply Last reply
                        0
                        • I Offline
                          I Offline
                          imrrk
                          wrote on last edited by
                          #79

                          ok andre and gerolf,thanks for ur information,I will check out the doc and come up with some possibilities..

                          regards
                          imrrk

                          1 Reply Last reply
                          0
                          • B Offline
                            B Offline
                            BorahAnshuman
                            wrote on last edited by
                            #80

                            hello friends

                            i want to change the font color for dates of calendar according to holidays ...for that i have used Qtextformat...but dont know hw can i use it to change the color of the font

                            1 Reply Last reply
                            0
                            • A Offline
                              A Offline
                              andre
                              wrote on last edited by
                              #81

                              The last reply here I moved over from "this":http://developer.qt.nokia.com/forums/viewthread/5296/ topic.

                              imrrk/BorahAnshuman: please keep your topics in logical groups. It does not make sense to re-open a thread about how to format the dates in a QCalendarWidget in a topic that is about the relative performance of an application on device and in the simulator.

                              1 Reply Last reply
                              0
                              • A Offline
                                A Offline
                                andre
                                wrote on last edited by
                                #82

                                [quote author="BorahAnshuman" date="1303188835"]hello friends

                                i want to change the font color for dates of calendar according to holidays ...for that i have used Qtextformat...but dont know hw can i use it to change the color of the font[/quote]

                                If the background color of a cell is controlled by setBackground, then it did not occor to you to look into the documentation of setForeground?

                                [quote]
                                Sets the foreground brush to the specified brush. The foreground brush is mostly used to render text.

                                See also foreground(), clearForeground(), and setBackground().
                                [/quote]

                                1 Reply Last reply
                                0
                                • B Offline
                                  B Offline
                                  BorahAnshuman
                                  wrote on last edited by
                                  #83

                                  Thanks for ur reply...its working..

                                  1 Reply Last reply
                                  0
                                  • B Offline
                                    B Offline
                                    BorahAnshuman
                                    wrote on last edited by
                                    #84

                                    hello Andre

                                    sorry for sending the question again...

                                    how can i set backgroundImageUrl in each cell in calender…Actually i had use QTextCharformat for doing that but it not work..code i hv written is..
                                    @QTextCharFormat format;

                                    format.BackgroundImageUrl;@
                                    My question is how can i set image url here….any clue please suggest..
                                    thanks

                                    1 Reply Last reply
                                    0
                                    • A Offline
                                      A Offline
                                      andre
                                      wrote on last edited by
                                      #85

                                      I think you will need to use something like this:"

                                      @
                                      QUrl imageUrl;
                                      //set the url to some valid value
                                      format.setProperty(QTextFormat::BackgroundImageUrl, QVariant(imageUrl));
                                      @

                                      But I don't think that will work, because the QCalendarWidget documentation states:
                                      [quote]
                                      Only a subset of the properties in QTextCharFormat are used by the calendar widget. Currently, the foreground, background and font properties are used to determine the rendering of individual cells in the widget.[/quote]

                                      Seems like you can only use the QTextCharFormat for the simple stuff, not for the fancy stuff. If you need to put an image in a cell, you are going to need to subclass QCalendarWidget and reimplement paintCell to do the rendering of your cells yourself.

                                      1 Reply Last reply
                                      0
                                      • B Offline
                                        B Offline
                                        BorahAnshuman
                                        wrote on last edited by
                                        #86

                                        hello andre

                                        i had implement ur code like this..

                                        @QUrl url = QUrl::fromEncoded("http://baytrail.abag.ca.gov/vtour/map4/access/CyteHils/Trail_to_Red_Hill_Summit.JPG");

                                        safedate.setProperty(QTextCharFormat::BackgroundImageUrl,QVariant(url));//safedate is an object of QTextCharFormat
                                        
                                        ui->calendarWidget->setDateTextFormat(QDate(2011,4,19),startdate);@
                                        

                                        but its not working..is anything missing here

                                        regards
                                        Anshuman

                                        1 Reply Last reply
                                        0
                                        • I Offline
                                          I Offline
                                          imrrk
                                          wrote on last edited by
                                          #87

                                          hello andre,have you observed in the qcalendarwidget,at first time it shows the currentdate,but when we select a different date ,their is no such marker which tells that it is a currentdate,i mean to say that the currentdate should be underlined so that when a user selects a different date ,the currentdate can be identified by the underlined mark.

                                          Regards
                                          imrrk

                                          1 Reply Last reply
                                          0

                                          • Login

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