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.
QtWS25 Last Chance

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.
  • B Offline
    B Offline
    BorahAnshuman
    wrote on 19 Apr 2011, 10:16 last edited by
    #100

    hello volker

    actually i had read about QPainters but doesnt know hw to implement it..from where to start

    i had given a code,,u plz check it whether its ok to work or not..

    @QPainter* pPainter = new QPainter(this);
    pPainter->drawPixmap(rect(), QPixmap(":/images/bg.png"));@

    after that what should i do cant find it
    regards

    Anshuman

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on 19 Apr 2011, 10:37 last edited by
      #101

      Read the docs. If you really do so, you will find a link to an example that even contains drawing pixmaps. Grab it, play with it, adapt it. This all is really basic stuff, explained multiple times in the docs with uncountable examples in the docs. We're not going to do your homework!

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

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on 19 Apr 2011, 10:40 last edited by
        #102

        imrrk and/or Anshuman:

        I am really done with this thread. Please do all of us here, including first and foremost yourself, a big favor, and get yourself enrolled in a good programming course in C++. If they use Qt, than that is a bonus, but that is not even needed. Otherwise, perhaps you should draft up a document describing what you want to achieve (not how you want to do that), and get yourself a consultant to do the work for you. I think a good one can do what you have achieved in the course of weeks of postings and copy/pasting snippets you have managed to beg of the contributers here in a matter of an hour or so. As it stands, I doubt you are able to ever complete whatever project you are on, and I feel spending any more time on this issue is a waste.

        All the best of luck, I am signing off.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          BorahAnshuman
          wrote on 19 Apr 2011, 10:58 last edited by
          #103

          ok..volker and /andre..thanks..i will try my level b est in doing so..but if any doubt arises i will ask u..

          with regards
          Anshuman

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on 19 Apr 2011, 11:28 last edited by
            #104

            [quote author="BorahAnshuman" date="1303210680"]ok..volker and /andre..thanks..i will try my level b est in doing so..but if any doubt arises i will ask u..

            with regards
            Anshuman[/quote]

            You (in plural or singular meaning - choose whatever you want) may ask, but don't expect any further answers. I step out too.

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

            1 Reply Last reply
            0
            • B Offline
              B Offline
              BorahAnshuman
              wrote on 20 Apr 2011, 10:08 last edited by
              #105

              Hello Volker

              as per ur suggestion i hv read QPainter class in QT..as per ur discussion i hv tried this code in setting backgroundImage in a particular cell in CalenderWidget but an error occur..cn u please check the error..

              @void PainterApp::paintEvent(QPaintEvent *)
              {
              QPainter painter(this);
              QRectF target(30.0, 40.0, 80.0, 60.0);
              QRectF source(30.0, 40.0, 70.0, 40.0);
              QImage image("C:/QTWork/back-icon.png");

                painter.drawImage(target, image, source);
              
                ui->calendarWidget->paintCell(painter,target,QDate::currentDate());
              
               painter.end();
              

              }@

              regards
              Anshuman

              1 Reply Last reply
              0
              • V Offline
                V Offline
                vinb
                wrote on 20 Apr 2011, 11:46 last edited by
                #106

                Why u using a paint event handler to do the painting?
                And if you ask to check the error, then why i dont see any output?
                Pleae post your error, or even better make a small app in wich your problem occurs and post it.

                Edit:
                On a site where trolls are super admin, it doesnt mean that you must "troll" yourself.

                1 Reply Last reply
                0
                • Z Offline
                  Z Offline
                  ZapB
                  wrote on 20 Apr 2011, 11:55 last edited by
                  #107

                  What are you doing? To get custom painting do this:

                  Derive a class from QCalendarWidget

                  Reimplement the paintCell() protected virtual function to do you custom painting

                  Use your custom class in your app instead of QCalendarWidget

                  When you reimplement the paintCell() function I suggest you make the changes from the base class version very incrementally so that you can see what the changes do and learn as you go along.

                  Nokia Certified Qt Specialist
                  Interested in hearing about Qt related work

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    goetz
                    wrote on 20 Apr 2011, 12:04 last edited by
                    #108

                    [quote author="BorahAnshuman" date="1303294092"]Hello Volker

                    as per ur suggestion i hv read QPainter class in QT..as per ur discussion i hv tried this code in setting backgroundImage in a particular cell in CalenderWidget but an error occur..cn u please check the error..

                    regards
                    Anshuman[/quote]

                    What was so unclear about my last statement?

                    [quote author="Volker" date="1303212502"]
                    You (in plural or singular meaning - choose whatever you want) may ask, but don't expect any further answers. I step out too.[/quote]

                    Are you trying to troll me?

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

                    1 Reply Last reply
                    0
                    • B Offline
                      B Offline
                      BorahAnshuman
                      wrote on 20 Apr 2011, 12:19 last edited by
                      #109

                      hello ZapB

                      Actually i inherit Qdialog and QCalenderWidget class..now when i build my app the following error ocurrs...can anyone suggest me why is occur..

                      Error r....

                      Rquest for member show() is ambiguous //show in main .cpp

                      the code i hv wrritten is:

                      @class PainterApp : public QDialog,public QCalendarWidget
                      {
                      Q_OBJECT

                      public:
                      explicit PainterApp(QWidget *parent = 0);
                      ~PainterApp();

                      private:
                      Ui::PainterApp *ui;
                      };
                      @
                      @void PainterApp::paintCell(QPainter * painter, const QRect & rect, const QDate & date ) const{

                      QRectF target(30.0, 40.0, 80.0, 60.0);
                      QRectF source(30.0, 40.0, 70.0, 40.0);
                      QImage image("C:/QTWork/back-icon.png");
                      
                      
                      painter->drawImage(target, image, source);
                      ui->calendarWidget->paintCell(painter,rect,date.currentDate());
                      

                      }@
                      with reagrds
                      Anshuman

                      1 Reply Last reply
                      0
                      • I Offline
                        I Offline
                        imrrk
                        wrote on 20 Apr 2011, 12:26 last edited by
                        #110

                        hello anshuman
                        bq. class PainterApp : public QDialog,public QCalendarWidget

                        this should in this way
                        class PainterApp : public QDialog,public Ui::Dialog//name of your form..

                        1 Reply Last reply
                        0
                        • Z Offline
                          Z Offline
                          ZapB
                          wrote on 20 Apr 2011, 12:39 last edited by
                          #111

                          That's because you are trying something that is not allowed and makes no sense when you think about it. The calendar widget will be shown within a dialog. The calendar widget is not a dialog. So use composition not inheritcance for the dialog aspect.

                          @
                          class MyCalendarWidget : public QCalendarWidget
                          {
                          ...
                          protected:
                          virtual void paintCell(QPainter* painter, const QRectF& rect, const QDate& date)
                          {
                          // Do custom painting here!!! See base class for default implementation and ideas
                          }
                          };

                          ...
                          ...
                          ...

                          class MyDialog : public QDialog
                          {
                          ...
                          };
                          @

                          Nokia Certified Qt Specialist
                          Interested in hearing about Qt related work

                          1 Reply Last reply
                          0
                          • B Offline
                            B Offline
                            BorahAnshuman
                            wrote on 20 Apr 2011, 12:48 last edited by
                            #112

                            Hello ZapB

                            thanks for ur reply..

                            Actually when i use the code like that

                            class PainterApp : public QDialog,public Ui::Dialog//name of your form..

                            than error is

                            // invalid use of incomplete type struct Ui::PainterApp//my form name come..

                            and one more thing i hv calender widget present in QtDesigner..which means i havent create my own custom calender..

                            regards
                            Anshuman

                            1 Reply Last reply
                            0
                            • Z Offline
                              Z Offline
                              ZapB
                              wrote on 20 Apr 2011, 12:53 last edited by
                              #113

                              [quote author="BorahAnshuman" date="1303303682"]Hello ZapB
                              and one more thing i hv calender widget present in QtDesigner..which means i havent create my own custom calender..
                              [/quote]

                              So do what I suggested and create one. You cannot override the paintCell() function if you do not have a sub-class of QCalendarWidget can you? This is basic C++.

                              Nokia Certified Qt Specialist
                              Interested in hearing about Qt related work

                              1 Reply Last reply
                              0
                              • B Offline
                                B Offline
                                BorahAnshuman
                                wrote on 20 Apr 2011, 13:13 last edited by
                                #114

                                ok ZapB I am sending my code u please check it..now no error signifies but nothing display in the cell..

                                @namespace Ui {
                                class PainterApp;
                                }
                                class MyCalendarWidget : public QCalendarWidget
                                {
                                private:
                                Ui::PainterApp ui;
                                protected:
                                virtual void paintCell(QPainter
                                painter, const QRectF& rect, const QDate& date);

                                };
                                class PainterApp : public QDialog
                                {
                                Q_OBJECT

                                public:
                                explicit PainterApp(QWidget *parent = 0);
                                ~PainterApp();

                                private:
                                Ui::PainterApp *ui;
                                private slots:

                                };@

                                @#include "painterapp.h"
                                #include "ui_painterapp.h"

                                PainterApp::PainterApp(QWidget *parent) :
                                QDialog(parent),
                                ui(new Ui::PainterApp)
                                {
                                ui->setupUi(this);

                                }
                                void MyCalendarWidget::paintCell(QPainter* painter, const QRectF& rect, const QDate& date)
                                {

                                rect(30.0, 40.0, 80.0, 60.0);
                                QImage image("C:/QTWork/back-icon.png");
                                
                                
                                painter->drawImage(rect, image, rect);
                                ui->calendarWidget->paintCell(painter,rect,date.currentDate());
                                

                                }
                                @

                                regards
                                Anshuman

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

                                  A few issues for you to consider/fix:

                                  Whay are your trying to change the rect passed into the paintCell() call. This is setup to tell you where to draw by the base class. Do not change it.

                                  Why are you trying to include the ui for something totally unrelated into your sub-class of QCalendarWidget?

                                  It seems you have no conceptual idea of how Qt widgets, dialogs, ui files etc relate to each other. I respectfully suggest that you go work through some of the many examples and tutorials shipped with Qt.

                                  Nokia Certified Qt Specialist
                                  Interested in hearing about Qt related work

                                  1 Reply Last reply
                                  0
                                  • B Offline
                                    B Offline
                                    BorahAnshuman
                                    wrote on 20 Apr 2011, 13:35 last edited by
                                    #116

                                    hi Zapb

                                    Actually i am new in Qt..more ever all of other people are new in Qt..so no one was there to guide me..ok i will..if u dont mind can u sent some material regarding Qt..actually i hv go through the documentation but it difficult to understand..

                                    if possible u can send me some material regarding Qt i my email address
                                    borah.anshu@gmail.com

                                    with regards
                                    Anshuman

                                    1 Reply Last reply
                                    0
                                    • D Offline
                                      D Offline
                                      DenisKormalev
                                      wrote on 20 Apr 2011, 13:37 last edited by
                                      #117

                                      Qt Documentation and examples shipped with Qt are the best docs and materials for learning Qt I think.

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

                                        Launch the qtdemo application. Find an example that interests you. Launch it and then read the docs about it.

                                        Nokia Certified Qt Specialist
                                        Interested in hearing about Qt related work

                                        1 Reply Last reply
                                        0
                                        • Kiran KumarK Offline
                                          Kiran KumarK Offline
                                          Kiran Kumar
                                          wrote on 15 Dec 2016, 11:21 last edited by
                                          #119

                                          You can reffer to this link as an example http://doc.qt.io/qt-5/qtwidgets-widgets-calendarwidget-example.html

                                          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